Results 1 to 13 of 13

Thread: Simple: Operator overloading with heap objects

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    76
    Thanked 37 Times in 32 Posts

    Default Re: Simple: Operator overloading with heap objects

    Sure nothing is stopping you from doing this.

    But you probably wouldn't want to do this kind of overloading as you are giving a new meaning to the == operator on pointers. Many a times the users of your code would not think that you are comparing the values.
    We can't solve problems by using the same kind of thinking we used when we created them

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Simple: Operator overloading with heap objects

    Quote Originally Posted by sunil.thaha View Post
    But you probably wouldn't want to do this kind of overloading as you are giving a new meaning to the == operator on pointers. Many a times the users of your code would not think that you are comparing the values.
    That's why it's impossible in C++

  3. #3
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    76
    Thanked 37 Times in 32 Posts

    Default Re: Simple: Operator overloading with heap objects

    That's why it's impossible in C++
    You are absolutely right. And thank you spotting out our mistake. I will never forget this

    BTW: did you try out what was said here. Or you got it at the first go ?
    We can't solve problems by using the same kind of thinking we used when we created them

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Simple: Operator overloading with heap objects

    Quote Originally Posted by sunil.thaha View Post
    did you try out what was said here. Or you got it at the first go ?
    I knew that it's impossible, but I've checked it just to be sure.

  5. #5
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 127 Times in 121 Posts

    Default Re: Simple: Operator overloading with heap objects

    Quote Originally Posted by jacek View Post
    I knew that it's impossible, but I've checked it just to be sure.
    Just curious : what error was thrown by the compiler??? (don't tell me "check it on your own" because I just can't ATM...)
    Current Qt projects : QCodeEdit, RotiDeCode

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Simple: Operator overloading with heap objects

    Quote Originally Posted by fullmetalcoder View Post
    Just curious : what error was thrown by the compiler???
    Something like: "at least one of operator arguments must be a class or an enum".

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Simple: Operator overloading with heap objects

    I wonder if the behaviour is simmilar for all popular compilers.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    28
    Thanked 976 Times in 912 Posts

    Default Re: Simple: Operator overloading with heap objects

    Quote Originally Posted by wysota View Post
    I wonder if the behaviour is simmilar for all popular compilers.
    It should be, at least if they are C++ compilers:
    An operator function shall either be a non-static member function or be a non-member function and have at least one parameter whose type is a class, a reference to a class, an enumeration, or a reference to an enumeration.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.