Results 1 to 3 of 3

Thread: operator=

  1. #1

    Thread Starter
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Unhappy operator=

    i have this class:

    PHP Code:
    class SubclassedObject    {
    public:
        
    MessageAnswer MsgResponse//

        
    SubclassedObject operator= (SubclassedObject);

        
    LRESULT CALLBACK SubclassWndProc(HWND hwndUINT MessageWPARAM 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
    Amon Ra
    The Power of Learning.

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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;
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Anyway, you can't assign a class member function as a wndproc...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width