Reputation: 173
I am trying to create a map full of strings as keys and integers as values. The problem begins when I try and search with it. Can someone tell me where I went wrong? Is it that I have two Maps in the same statement?
invale is "ale"
roomno = 2;
// roomlist is a map
// rinventory is another map
if( roomlist[roomno].rinventory.find( invale ) != map<string, int>::end());
The error I get follows. What overloaded function? It really is a lengthy error.
error C2668: 'std::_Tree<_Traits>::end' : ambiguous call to overloaded function
1> with
1> [
1> _Traits=std::_Tmap_traits<std::string,int,std::less<std::string>,std::allocator<std::pair<const std::string,int>>,false>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\xtree(569): could be 'std::_Tree<_Traits>::const_iterator std::_Tree<_Traits>::end(void) const'
1> with
1> [
1> _Traits=std::_Tmap_traits<std::string,int,std::less<std::string>,std::allocator<std::pair<const std::string,int>>,false>
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\xtree(564): or 'std::_Tree<_Traits>::iterator std::_Tree<_Traits>::end(void)'
1> with
1> [
1> _Traits=std::_Tmap_traits<std::string,int,std::less<std::string>,std::allocator<std::pair<const std::string,int>>,false>
1> ]
1> while trying to match the argument list '(void)'
Thank you in advance.
Upvotes: 1
Views: 325
Reputation: 4924
It should be
if( roomlist[roomno].rinventory.find( invale ) != roomlist[roomno].rinventory.end());
Upvotes: 0
Reputation: 27250
Try changing it to:
if( roomlist[roomno].rinventory.find( invale ) != roomlist[roomno].rinventory.end());
Upvotes: 3
Reputation: 64223
map::end()
method is not static.
The proper way is like this :
map<string, int>::iterator it = roomlist[roomno].rinventory.find( invale );
if( it != roomlist[roomno].rinventory.end())
// do stuff
Upvotes: 0