map <vector <string>,string&gt;给我一个错误</vector <string>

时间:2013-10-13 10:21:43

标签: c++ vector

我正在尝试创建一个地图,它将字符串的矢量设置为键,将字符串设置为值,但它一直给我这个错误:

invalid operands to binary expression
    ('constant Vector.....' and 'constant Vector....) 

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

它们的编写方式Vector<string>表明它是一个自定义类。此类需要operator<作为Map's键,但可能没有。{1}}。你需要添加

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;
    }
}