Error C2662 Const
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you c2662 c++ might have Meta Discuss the workings and policies of this site error c2662 conversion loses qualifiers About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or error c2662 cannot convert 'this' pointer from posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of
Cannot Convert This Pointer From Const To &
4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up c++ error C2662 cannot convert 'this' pointer from 'const Type' to 'Type &' up vote 17 down vote favorite 6 I am trying to overload the c++ operator== but im getting some errors... error C2662: 'CombatEvent::getType' const method : cannot convert 'this' pointer from 'const CombatEvent' to 'CombatEvent &' this error is at this line if (lhs.getType() == rhs.getType()) see the code bellow: class CombatEvent { public: CombatEvent(void); ~CombatEvent(void); enum CombatEventType { AttackingType, ... LowResourcesType }; CombatEventType getType(); BaseAgent* getAgent(); friend bool operator<(const CombatEvent& lhs, const CombatEvent& rhs) { if (lhs.getType() == rhs.getType()) return true; return false; } friend bool operator==(const CombatEvent& lhs, const CombatEvent& rhs) { if (lhs.getType() == rhs.getType()) return true; return false; } private: UnitType unitType; } can anybody help? c++ operator-overloading syntax-error friend-function share|improve this question asked Aug 22 '12 at 7:33 thiagoh 1,74262143 add a comment| 3 Answers 3 active oldest votes up vote 36 down vote accepted CombatEventType getType(); needs to be CombatEventType getType() const; Your compiler is complaining because the function is being given a const object that you're trying to call a non-const function on. When a function gets a const object, all calls to it have to be const through
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us error c2662 cannot convert this pointer from const to conversion loses qualifiers Learn more about Stack Overflow the company Business Learn more about hiring developers
Const_cast Example
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack
Const Function
Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up error C2662 cannot convert from const to http://stackoverflow.com/questions/12068301/c-error-c2662-cannot-convert-this-pointer-from-const-type-to-type reference up vote 2 down vote favorite this is my first post on stack overflow, and I hope to join the community in the future. I'm in the midst of programming a hash table implementation for an ADT class; most of my methods are up to par within the bounds of the assignment, but this is giving me grief. In this test application which I have been http://stackoverflow.com/questions/20319540/error-c2662-cannot-convert-from-const-to-reference using to test various functions as I write them, I'm recieving the error "error C2662: 'customer::getPhone': cannot convert 'this' ponter from 'const customer' to 'customer &' in reference to the lines "cursor = find_ptr(entry.getPhone());" and "list_head_insert(data[hash(entry.getPhone())], entry);" My code implementation for the functions is as follows: template
Forum Visual C++ & C++ Programming Visual C++ Programming [RESOLVED] error C2662: cannot convert 'this' pointer http://forums.codeguru.com/showthread.php?416873-RESOLVED-error-C2662-cannot-convert-this-pointer-from-const-Item-to-Item-amp from 'const Item' to 'Item &' If this is your first https://forum.qt.io/topic/7774/solved-c2662-function-cannot-convert-this-pointer-from-type1-to-type2 visit, be sure to check out the FAQ by clicking the link above. You may have to register or Login before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the error c2662 selection below. Results 1 to 11 of 11 Thread: [RESOLVED] error C2662: cannot convert 'this' pointer from 'const Item' to 'Item &' Tweet Thread Tools Show Printable Version Email this Page… Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode March 6th, 2007,07:07 AM #1 Mybowlcut View Profile View Forum Posts conversion loses qualifiers Visit Homepage Senior Member Join Date Nov 2006 Location Australia Posts 1,569 [RESOLVED] error C2662: cannot convert 'this' pointer from 'const Item' to 'Item &' Hi guys! The error: Code: error C2662: 'Item::GetName' : cannot convert 'this' pointer from 'const Item' to 'Item &' My class definition: Code: class Inventory { public: Inventory(vector
download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript). Home Qt Development General and Desktop