overloading operator in C++

This is a discussion on overloading operator in C++ within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by -EquinoX- okay... some say that using operator cast will allow me to use one function definition Beware ...

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,012
    Quote Originally Posted by -EquinoX- View Post
    okay... some say that using operator cast will allow me to use one function definition
    Beware of those. They are the source of much evil. You must use them with care.
    Saving a function isn't enough. They cause all sorts of problems.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by Elysia View Post
    Because in the first case, the compiler looks for a function with a parameter list that looks like const String&, int, and in the second the reverse. Since no such function exists...
    The reason for the need of two is probably technical. Such as the compiler cannot guarantee no side effects.
    I don't think the reason for this is technical at all. I think it's fairly easy: you can't assume that a*b == b*a. That is, not all multiplications are commutative. Sure, the multiplication of two integers is, but matrix multiplication is not, for instance. So let's say we have operator*(Matrix1Type, Matrix2Type) and the operator* of the two reversed is called, we get unexpected results, which are probably fairly hard to debug as well.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,012
    That is kind of what I meant by technical. The compiler cannot assume that the two will do the same thing.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with Operator Overloading
    By Swerve in forum C++ Programming
    Replies: 6
    Last Post: 10-24-2009, 12:01 AM
  2. Overloading operators
    By ugmusicbiz in forum C++ Programming
    Replies: 2
    Last Post: 02-13-2009, 01:41 PM
  3. unary operator overloading and classes
    By coletek in forum C++ Programming
    Replies: 9
    Last Post: 01-10-2009, 02:14 AM
  4. Overloading operator ==
    By anon in forum C++ Programming
    Replies: 4
    Last Post: 05-10-2006, 04:26 PM
  5. overloading
    By theLukerBoy in forum C++ Programming
    Replies: 6
    Last Post: 11-04-2002, 08:49 PM

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