简体   繁体   English

binary'==':找不到带有'std :: string'类型的左手操作数的运算符(或者没有可接受的转换)

[英]binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)

I am writing a template class function comparing std::strings. 我正在编写一个比较std :: strings的模板类函数。 std::string is the template parameter. std :: string是模板参数。 My problem is that I can't compare two const string with "==" operator, then I think I create two non-const temporary string variables to performe the comparation, but it still can't compile. 我的问题是我无法将两个const字符串与“==”运算符进行比较,那么我认为我创建了两个非const临时字符串变量来进行比较,但它仍然无法编译。 Don't know why. 不知道为什么。

class VGraph is instanced as VGraph<std::string, std::string> myGraph; 类VGraph实例为VGraph<std::string, std::string> myGraph;

template <typename V, typename E>
size_t VGraph<V, E>::find(const V& vert)
{
    V temp = vert; // (1)
    for (size_t i=0; i<graph.size(); i++)
    {
        V noneConst = graph[i].getVertex(); // (2)
        if (temp==noneConst)// I think broblem is here, and tried to fix using (1)(2)
            return i;
    }
    return graph.size();
}

Prototype of related function 相关功能的原型

template <typename V, typename E>
const V& VVertex<V, E>::getVertex();

You probably forgot an explicit: 你可能忘记了一个明确的:

#include <string>

The std::string class is defined by a another header you included, but not the operator == . std::string类由您包含的另一个头定义,但不是operator ==

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误 C2678:二进制“=”:未找到采用“const std::string”类型的左操作数的运算符(或没有可接受的转换) - error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const std::string' (or there is no acceptable conversion) 错误C2678:二进制&#39;&gt;&gt;&#39;:未找到采用&#39;std :: istream&#39;类型的左操作数的运算符(或没有可接受的转换) - error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::istream' (or there is no acceptable conversion) 错误1错误C2678:二进制&#39;!=&#39;:未找到采用&#39;std :: ofstream&#39;类型的左操作数的运算符(或没有可接受的转换) - Error 1 error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::ofstream' (or there is no acceptable conversion) 错误C2678:二进制'<<':找不到运算符,它接受类型为'const std :: ofstream'的左手操作数(或者没有可接受的转换) - Error C2678: binary '<<' : no operator found which takes a left-hand operand of type 'const std::ofstream' (or there is no acceptable conversion) C2678二进制&#39;==&#39;:找不到使用&#39;Card&#39;类型的左操作数的运算符(或者没有可接受的转换) - C2678 binary '==': no operator found which takes a left-hand operand of type 'Card' (or there is no acceptable conversion) 错误C2678:二进制'==':找不到哪个运算符采用类型的左操作数(或者没有可接受的转换) - error C2678: binary '==' : no operator found which takes a left-hand operand of type (or there is no acceptable conversion) 二进制“==”:未找到采用“Enemy”类型左侧操作数的运算符(或没有可接受的转换) - binary '==': no operator found which takes a left-hand operand of type 'Enemy' (or there is no acceptable conversion) 二进制&#39;=&#39;:未找到采用&#39;_Ty&#39;类型的左操作数的运算符(或没有可接受的转换) - binary '=': no operator found which takes a left-hand operand of type '_Ty' (or there is no acceptable conversion) 错误C2678:二进制'=':找不到哪个运算符带有'const Recipe'类型的左手操作数(或者没有可接受的转换) - error C2678: binary '=' : no operator found which takes a left-hand operand of type 'const Recipe' (or there is no acceptable conversion) 错误C2678:二进制&#39;+&#39;:未找到采用&#39;volatile A&#39;类型的左操作数的运算符(或者没有可接受的转换) - error C2678: binary '+': no operator found which takes a left-hand operand of type 'volatile A' (or there is no acceptable conversion)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM