Avatar ·

Erro "passing const xxx as 'this' argument discards qualifiers" em C++: como corrigir

Olá! Sou um desenvolvedor C++ iniciante e encontrei um erro que não consigo entender. Estou tentando usar std::set para armazenar objetos personalizados, mas o compilador está gerando o erro:\n\n
error: passing 'const MyClass' as 'this' argument of 'bool MyClass::operator<(const MyClass&)' discards qualifiers [-fpermissive]
\n\nAqui está meu código:\n\n
#include <iostream>\n#include <set>\n\nclass MyClass {\npublic:\n    MyClass(int val) : value(val) {}\n\n    bool operator<(const MyClass& other) {\n        return this->value < other.value;\n    }\n\n    int getValue() const { return value; }\n\nprivate:\n    int value;\n};\n\nint main() {\n    std::set<MyClass> mySet;\n    mySet.insert(MyClass(10));\n    mySet.insert(MyClass(5));\n    \n