Yurttas/PL/OOL/Cplusplus/F/03/02/00/05.html

Dr.Salih Yurttas - yurttas@zcubes.com
programming languages - design principles, implementation constructs
c++

  1. abstraction mechanisms: classes and operator overloading
    1. class/object construction - operator overloading
      1. binary and unary operators -
        • An operator function intended to accept a basic type as its first operand cannot be a member function.
        • For example, consider adding a complex variable aa to the integer 2; aa+2 can, with a suitably declared member function, be interpreted as aa.operator+(2), but 2+aa cannot because there is no class int for which to define + to mean 2.operator+(aa).
        • Even if there were, two different member functions would be needed to cope with 2+aa and aa+2. Because the compiler does not know the meaning of a user-defined +, it cannot assume that it is commutative and interpret 2+aa as aa+2. This example is trivially handled by using nonmember functions. << |

1 | basic facilities << 3 >> class derivation | 5 | 6 | 7 | 8