I am writing a template class function comparing std::strings. std::string is the template parameter. 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. Don't know why.
class VGraph is instanced 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 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 ==
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With