I cannot create operators for my class
-
Hello
I try to create operators for my class
in the header I have
@
class Connectoin{
public :
.
.
.
bool operator()(const Connection &first, const Connection &other) const;
bool operator<(const Connection &other) const;
private:
.
.
.
@
and in the source file I implement it@
bool Connection::operator()(const Connection &first, const Connection &other)const
{
return (first.getName() < other.getName());
}bool Connection::operator<(const Connection &other)const
{
return (this->name < other.getName());
}
@
all getter methods I have defines as const,
The error is "passing 'const Connection' as 'this' argument of 'const QString Connection::getName()' discards qualifiers [-fpermissive]"what should I do?
-
bq. what should I do?
Post here the code of getName() ;)
The error is not about operators, but that getName has a non-const context. Are you 100% sure the signature of getName() is const? The compiler seems to disagree on that ;)
const QString Connection::getName() returns a const QString (which is weird really) but the method is not const itself. It should be QString Connection::getName() const