-
operator=
i have this class:
PHP Code:
class SubclassedObject {
public:
MessageAnswer MsgResponse; //
SubclassedObject operator= (SubclassedObject);
LRESULT CALLBACK SubclassWndProc(HWND hwnd, UINT Message, WPARAM wParam,
LPARAM lParam);
};
i have tried this as the operator=
PHP Code:
SubclassedObject SubclassedObject::operator = (SubclassedObject sobj)
{
this->MsgResponse = sobj.MsgResponse;
this->SubclassWndProc = sobj.SubclassWndProc;
return this;
}
but it gives me errors such as there
Code:
c:\my documents\subclasspractice\easysubclass.h(46) : error C2659: '=' : overloaded function as left operand
c:\my documents\subclasspractice\easysubclass.h(47) : error C2664: '__thiscall SubclassedObject::SubclassedObject(const class SubclassedObject &)' : cannot convert parameter 1 from 'class SubclassedObject *const ' to 'const class SubclassedObject &'
Reason: cannot convert from 'class SubclassedObject *const ' to 'const class SubclassedObject'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\my documents\subclasspractice\easysubclass.h(47) : error C2553: no legal conversion of return value to return type 'class SubclassedObject *'
can anyone help me? thanks
-
c:\my documents\subclasspractice\easysubclass.h(46) : error C2659: '=' : overloaded function as left operand
you are assigning a function, i guess it's not what you intend to do
c:\my documents\subclasspractice\easysubclass.h(47) : error C2664: '__thiscall SubclassedObject::SubclassedObject(const class SubclassedObject &)' : cannot convert parameter 1 from 'class SubclassedObject *const ' to 'const class SubclassedObject &'
Reason: cannot convert from 'class SubclassedObject *const ' to 'const class SubclassedObject'
No constructor could take the source type, or constructor overload resolution was ambiguous
c:\my documents\subclasspractice\easysubclass.h(47) : error C2553: no legal conversion of return value to return type 'class SubclassedObject *'
= should return a reference to *this change both in the header and the function
In fact unless you have any dynamically allocated data in your object, similar to copy constructors you could just assign the whole object: return *this=sobj;
-
Anyway, you can't assign a class member function as a wndproc...