Operator= Overloading
-
Hi All, I'm trying to overload the assignment (=) operator so that I can achieve the following: int x = myclass; instead of: int x = myclass.Value(); I am implementing it as follows: class CMyClass { private: int m_nValue; public: int& operator=(CMyClass& class); int Value() { return m_nValue; }; }; int& CMyClass::operator=(CMyClass& class) { return class.Value(); } But I keep on getting a compiler errors either saying that there is no suitable conversion, or that it cannot convert from CMyClass to int. Clearly my syntax (or something) is screwed, so how can I fix it ? Thanks OD
-
Hi All, I'm trying to overload the assignment (=) operator so that I can achieve the following: int x = myclass; instead of: int x = myclass.Value(); I am implementing it as follows: class CMyClass { private: int m_nValue; public: int& operator=(CMyClass& class); int Value() { return m_nValue; }; }; int& CMyClass::operator=(CMyClass& class) { return class.Value(); } But I keep on getting a compiler errors either saying that there is no suitable conversion, or that it cannot convert from CMyClass to int. Clearly my syntax (or something) is screwed, so how can I fix it ? Thanks OD
This forum is meant for managed C++. You have rightly asked it in VC++[^] forum. So, please dont cross-post.
Prasad Notifier using ATL | Operator new[],delete[][^]