[英]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.