Binary '==': no ​​operator was found that accepts a left operand of type 'std :: string' (or not an acceptable conversion)

I am writing a template class function by comparing std :: strings. std :: string - template parameter. My problem is that I cannot compare two constant strings with the "==" operator, then I think that I am creating two non-constant temporary string variables to perform the comparison, but it still cannot compile. I do not know why.

the VGraph class is defined as 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 related function

 template <typename V, typename E> const V& VVertex<V, E>::getVertex(); 
+4
source share
1 answer

You probably forgot the explicit:

 #include <string> 

The std::string defined by another header that you include, but not the == operator.

+18
source

Source: https://habr.com/ru/post/1399687/


All Articles