Adding comment on code 


-1
down vote
favorite
I am trying to create a map which sets a vector of string as the key and a string as the value but it keeps giving me this error:

invalid operands to binary expression
    ('constant Vector.....' and 'constant Vector....) 
Any ideas please?

c++ vector
share|improve this question
edited Oct 14 '13 at 0:40

asked Oct 13 '13 at 10:21

otch92
12
7	  	
The way they are written Vector<string> suggests it's a custom class. This class needs an operator< to be usable an a Map's key, but probably doesn't have one. –  Daniel Frey Oct 13 '13 at 10:24 
4	  	
Since neither Map nor Vector are standard library classes, shall we assume they're of your own creation? –  WhozCraig Oct 13 '13 at 10:24 
4	  	
Are Map and Vector std::map and std::vector respectively? And which line is the source of the error? –  juanchopanza Oct 13 '13 at 10:24 
  	  	
@DanielFrey that should be the answer –  littleadv Oct 13 '13 at 10:25
  	  	
Heh. I just learned something new from this question. @juanchopanza, has std::vector<> always had a free-function operator < in the standard library? cppref says its pre-11. –  WhozCraig Oct 13 '13 at 10:28
show 5 more comments
1 Answer
activeoldestvotes
up vote
1
down vote
The way they are written Vector<string> suggests it's a custom class. This class needs an operator< to be usable as a Map's key, but probably doesn't have one. You need to add

bool operator<( const Vector<string>& lhs, const Vector<string>& rhs )
{
    int pos = 0;
    while( true ) {
        if( pos == lhs.size() && pos == rhs.size() ) return false;
        if( pos == lhs.size() ) return true;
        if( pos == rhs.size() ) return false;
        if( lhs[ pos ] < rhs[ pos ] ) return true;
        if( rhs[ pos ] < lhs[ pos ] ) return false;
        ++pos;
    }
}