2016-01-03 10 views
0

Как вставить элемент на следующую карту?Как я могу вставить в карту с несколькими картами?

map<Longitud,multimap<Latitud, ID> > posicionGeo; 

Я пытался вставить так:

posicionGeo.insert(make_pair(x.getLongitude(),make_pair(x.getLatitude(),x.getID()))); 

, но это не работает. Выбрасывает эту ошибку:

In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64:0, 
       from /usr/include/c++/4.8/bits/char_traits.h:39, 
       from /usr/include/c++/4.8/string:40, 
       from fecha.h:9, 
       from principal.cpp:2: 
/usr/include/c++/4.8/bits/stl_pair.h: In instantiation of ‘std::pair<_T1, _T2>::pair(const std::pair<_U1, _U2>&) [with _U1 = int; _U2 = std::pair<int, int>; _T1 = const float; _T2 = std::multimap<float, unsigned int>]’: 
CrimeSearch.hxx:33:51: required from here 
/usr/include/c++/4.8/bits/stl_pair.h:119:39: error: no matching function for call to ‘std::multimap<float, unsigned int>::multimap(const std::pair<int, int>&)’ 
    : first(__p.first), second(__p.second) { } 
            ^
/usr/include/c++/4.8/bits/stl_pair.h:119:39: note: candidates are: 
In file included from /usr/include/c++/4.8/map:62:0, 
       from CrimeSearch.h:9, 
       from principal.cpp:4: 
/usr/include/c++/4.8/bits/stl_multimap.h:235:9: note: template<class _InputIterator> std::multimap<_Key, _Tp, _Compare, _Alloc>::multimap(_InputIterator, _InputIterator, const _Compare&, const allocator_type&) 
     multimap(_InputIterator __first, _InputIterator __last, 
     ^
/usr/include/c++/4.8/bits/stl_multimap.h:235:9: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64:0, 
       from /usr/include/c++/4.8/bits/char_traits.h:39, 
       from /usr/include/c++/4.8/string:40, 
       from fecha.h:9, 
       from principal.cpp:2: 
/usr/include/c++/4.8/bits/stl_pair.h:119:39: note: candidate expects 4 arguments, 1 provided 
    : first(__p.first), second(__p.second) { } 
            ^
In file included from /usr/include/c++/4.8/map:62:0, 
       from CrimeSearch.h:9, 
       from principal.cpp:4: 
/usr/include/c++/4.8/bits/stl_multimap.h:219:9: note: template<class _InputIterator> std::multimap<_Key, _Tp, _Compare, _Alloc>::multimap(_InputIterator, _InputIterator) 
     multimap(_InputIterator __first, _InputIterator __last) 
     ^
/usr/include/c++/4.8/bits/stl_multimap.h:219:9: note: template argument deduction/substitution failed: 
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:64:0, 
       from /usr/include/c++/4.8/bits/char_traits.h:39, 
       from /usr/include/c++/4.8/string:40, 
       from fecha.h:9, 
       from principal.cpp:2: 
/usr/include/c++/4.8/bits/stl_pair.h:119:39: note: candidate expects 2 arguments, 1 provided 
    : first(__p.first), second(__p.second) { } 
            ^
In file included from /usr/include/c++/4.8/map:62:0, 
       from CrimeSearch.h:9, 
       from principal.cpp:4: 
/usr/include/c++/4.8/bits/stl_multimap.h:177:7: note: std::multimap<_Key, _Tp, _Compare, _Alloc>::multimap(const std::multimap<_Key, _Tp, _Compare, _Alloc>&) [with _Key = float; _Tp = unsigned int; _Compare = std::less<float>; _Alloc = std::allocator<std::pair<const float, unsigned int> >] 
     multimap(const multimap& __x) 
    ^
/usr/include/c++/4.8/bits/stl_multimap.h:177:7: note: no known conversion for argument 1 from ‘const std::pair<int, int>’ to ‘const std::multimap<float, unsigned int>&’ 
/usr/include/c++/4.8/bits/stl_multimap.h:166:7: note: std::multimap<_Key, _Tp, _Compare, _Alloc>::multimap(const _Compare&, const allocator_type&) [with _Key = float; _Tp = unsigned int; _Compare = std::less<float>; _Alloc = std::allocator<std::pair<const float, unsigned int> >; std::multimap<_Key, _Tp, _Compare, _Alloc>::allocator_type = std::allocator<std::pair<const float, unsigned int> >] 
     multimap(const _Compare& __comp, 
    ^
/usr/include/c++/4.8/bits/stl_multimap.h:166:7: note: no known conversion for argument 1 from ‘const std::pair<int, int>’ to ‘const std::less<float>&’ 
/usr/include/c++/4.8/bits/stl_multimap.h:157:7: note: std::multimap<_Key, _Tp, _Compare, _Alloc>::multimap() [with _Key = float; _Tp = unsigned int; _Compare = std::less<float>; _Alloc = std::allocator<std::pair<const float, unsigned int> >] 
     multimap() 
    ^
/usr/include/c++/4.8/bits/stl_multimap.h:157:7: note: candidate expects 0 arguments, 1 provided 

Похоже, что ваше сообщение в основном кода; добавьте еще несколько деталей. Похоже, что ваш пост - это в основном код; добавьте еще несколько деталей.

+2

Что значит «но не работает» означает, что оно бросает исключение, создает другое сообщение, не делает вставки, вставляет неправильную вещь и т. Д. Кроме того, включайте больше информации, таких как make_pair и 'multimap's деклараций. – blm

ответ

0

я найти решение, вы можете сделать вставку в два этапа:

multimap<Latitud, ID> mymap; 
    mymap.insert(make_pair(x.getLatitude(),x.getID())); 
posicionGeo.insert(make_pair(x.getLongitude(),mymap)); 

, но я не знаю, почему это:

posicionGeo.insert(make_pair(x.getLongitude(),make_pair(x.getLatitude(),x.getID()))); 

не работают, я думаю, что это то же самое.

Смежные вопросы