About Overloaded Operator. Please Help

This is a discussion on About Overloaded Operator. Please Help within the C++ Programming forums, part of the General Programming Boards category; I'm learning C++ Primer 4th Edition now. This book suggests that we should define the arithmetic and relational operators as ...

  1. #1
    C/C++Newbie Antigloss's Avatar
    Join Date
    May 2005
    Posts
    212

    About Overloaded Operator. Please Help

    I'm learning C++ Primer 4th Edition now. This book suggests that we should define the arithmetic and relational operators as nonmember functions. Why?

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    my guess would be so that you can make it communitive when mixing types for example

    MyType answer = MyType + 5; //operator+ can be define as member or non-member
    MyType answer = 5 + MyTyper; // can only be non-member

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    491
    One should also prefer non-member non-friend functions if possible:

    http://www.gotw.ca/gotw/084.htm

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 02:29 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  3. overloaded >> operator issue...
    By soulredemption in forum C++ Programming
    Replies: 2
    Last Post: 10-17-2005, 11:53 PM
  4. Cannot resolve overloaded function
    By Mithoric in forum C++ Programming
    Replies: 10
    Last Post: 11-29-2003, 03:40 AM
  5. overloaded on overloads
    By emceedee in forum C++ Programming
    Replies: 1
    Last Post: 03-31-2003, 02:14 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21