Thread: about overloading operators

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    451

    about overloading operators

    i always fail with overloading operators...i use C++11 for be more easy.
    can anyone explain to me how overloading operator?

    inside of class label:
    Code:
    HWND& operator=(const label &test)
        {
            return this->hwnd;
        }
    how i use it:
    Code:
    SetWindowText(label1, "left mouse button down");
    - SetWindowText() is for change the window caption;
    - label1 is 1 instance of label.
    the SetWindowText() function, 1st parameter must recive a HWND value. but i mistake with overloading operator

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    The operator = is generally used for assignment because, well, it's the assignment operator. So presumably you would want to do some sort of assigning.

    You labeled your second snippet as "how I use it" but you don't use it in the snippet (the = character does not appear anywhere), so why you think it is relevant is anybody's guess.

    EDIT: Or did you want a conversion operator? That has a different name. If this is true, then IMO the correct answer is to forget about conversions and provide a getter for the hwnd member:
    Code:
    SetWindowText(label1.GetHWND(), "left mouse button down");
    Last edited by tabstop; 01-29-2014 at 10:50 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Overloading operators
    By Shockey62 in forum C++ Programming
    Replies: 5
    Last Post: 04-23-2012, 11:23 AM
  2. overloading operators
    By yahn in forum C++ Programming
    Replies: 12
    Last Post: 08-13-2007, 12:30 PM
  3. Overloading >> and << operators
    By Basca in forum C++ Programming
    Replies: 3
    Last Post: 10-09-2006, 01:27 PM
  4. Help with using overloading operators
    By clueless159753 in forum C++ Programming
    Replies: 1
    Last Post: 12-10-2003, 11:48 AM
  5. Overloading Operators
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 08-19-2002, 02:23 PM