c++ - error C2678 : binary '<' : no operator found which takes a left-hand operand. ..(或者没有可接受的转换)

标签 c++ map

<分区>

这是我在 map 中查找值的代码:

bool myclass::getFreqFromCache( plVariablesConjunction& varABC, vector<plFloat>& freq )
{
std::map<plVariablesConjunction, std::vector<plFloat>>::iterator freqItr;
    freqItr = freqCache.find(varABC);

    if (freqItr != freqCache.end())
        {
        freq = freqItr->second;
        return true;
        }
 }

“PlVariablesConjunction”是 ProBT 库数据类型。它包含运算符“==”,如果发现两个变量相同则返回 true,否则返回 false。

这里是错误:

C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xfunctional(125): error C2678: binary '<' : no operator found which takes a left-hand operand of type 'const plVariablesConjunction' (or there is no acceptable conversion)
1>          E:\ProBT22\probt-spl-2.2.0-expires-20121130-vc10-dynamic-release\include\plSymbol.h(71): could be 'bool operator <(const plSymbol &,const plSymbol &)' [found using argument-dependent lookup]
1>          while trying to match the argument list '(const plVariablesConjunction, const plVariablesConjunction)'
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xfunctional(124) : while compiling class template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const'
1>          with
1>          [
1>              _Ty=plVariablesConjunction
1>          ]
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\map(71) : see reference to class template instantiation 'std::less<_Ty>' being compiled
1>          with
1>          [
1>              _Ty=plVariablesConjunction
1>          ]
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xtree(451) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled
1>          with
1>          [
1>              _Kty=plVariablesConjunction,
1>              _Ty=std::vector<plProbValue>,
1>              _Pr=std::less<plVariablesConjunction>,
1>              _Alloc=std::allocator<std::pair<const plVariablesConjunction,std::vector<plProbValue>>>,
1>              _Mfl=false
1>          ]
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xtree(520) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled
1>          with
1>          [
1>              _Traits=std::_Tmap_traits<plVariablesConjunction,std::vector<plProbValue>,std::less<plVariablesConjunction>,std::allocator<std::pair<const plVariablesConjunction,std::vector<plProbValue>>>,false>
1>          ]
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\xtree(659) : see reference to class template instantiation 'std::_Tree_val<_Traits>' being compiled
1>          with
1>          [
1>              _Traits=std::_Tmap_traits<plVariablesConjunction,std::vector<plProbValue>,std::less<plVariablesConjunction>,std::allocator<std::pair<const plVariablesConjunction,std::vector<plProbValue>>>,false>
1>          ]
1>          C:\Program Files\Microsoft Visual Studio 10.0\VC\include\map(81) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled
1>          with
1>          [
1>              _Traits=std::_Tmap_traits<plVariablesConjunction,std::vector<plProbValue>,std::less<plVariablesConjunction>,std::allocator<std::pair<const plVariablesConjunction,std::vector<plProbValue>>>,false>
1>          ]
1>          e:\probt22\work\yasin\testmmhcfinalversion\testmmhc_mi_probt_sw\mmhc\slidingWindow.h(55) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
1>          with
1>          [
1>              _Kty=plVariablesConjunction,
1>              _Ty=std::vector<plProbValue>
1>          ]

最佳答案

std::map (通常)实现为二叉搜索树,最常见的是红黑树。它需要为键值定义线性顺序以在树中找到正确的位置。这就是为什么 std::map尝试调用 operator<关于插入的键值。

你的类(class)没有提供operator< .要么定义 operator<为您的类(class)或为模板提供比较功能:std::map<plVariablesConjunction, std::vector<plFloat>, my_comparison_function> .

关于c++ - error C2678 : binary '<' : no operator found which takes a left-hand operand. ..(或者没有可接受的转换),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11647954/

相关文章:

qt - Qt的映射小部件

javascript - 禁用 anchor 跳

c++ - std::map 键类必须满足哪些要求才能成为有效键?

c++ - 内部类访问外部几个级别

c++ - 可变参数 lambda 与可变参数模板函数 : stricly equivalent?

c++ - cython 使用 nogil 创建字符串

javascript - 使用带有一个附加参数的函数的 map() 的 JS 回调

java - MapReduce canopy 聚类中心

c++ - 使用 gSOAP 时如何将数据从客户端传递到服务器?

c++ - 解析一个 int(x) 参数