Hi everyone,
I am quite new to C++ (coming from perl). As an exercise, I am currently trying to create a class to play with graphs.
I have a class Node in which I overload the == operator (to test the equality between two nodes). At the moment, I consider two nodes being similar if they have the same name.
When compiling I get the following error message.
Node.cpp: In member function ‘bool Node::operator==(const Node&)’:
Node.cpp:51: error: passing ‘const Node’ as ‘this’ argument of ‘std::string Node::getName()’ discards qualifiers
I would be very happy if somebody had an idea of the problem.
(Node.hpp)
class Node {
public:
Node(string);
Node(string, string);
// blabla
string getName();
bool operator==(const Node &) ;
// blabla
private:
string name; // node name
};
(functions '==' and getName() in Node.cpp)
bool Node::operator==(const Node &node) {
return node.getName() == getName();
}
string Node::getName() {
return this->name;
}