Avatar ·

C++ में "passing const xxx as 'this' argument discards qualifiers" त्रुटि: इसे कैसे ठीक करें

नमस्ते! मैं एक शुरुआती C++ डेवलपर हूँ, और मुझे एक त्रुटि मिली है जिसे मैं समझ नहीं पा रहा हूँ। मैं std::set का उपयोग करके कस्टम objects को स्टोर करने की कोशिश कर रहा हूँ, लेकिन compiler यह त्रुटि दे रहा है:\n\n
error: passing 'const MyClass' as 'this' argument of 'bool MyClass::operator<(const MyClass&)' discards qualifiers [-fpermissive]
\n\nयह रहा मेरा कोड:\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