Yurttas/PL/OOL/Cplusplus/F/03/02/00/05.html
Dr.Salih Yurttas - yurttas@zcubes.com
programming languages - design principles, implementation constructs
c++
- abstraction mechanisms: classes and operator overloading
- class/object construction - operator overloading
- 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 asaa.operator+(2)
, but2+aa
cannot because there is no classint
for which to define+
to mean2.operator+(aa)
. - Even if there were, two different member functions would be needed to cope with
2+aa
andaa+2
. Because the compiler does not know the meaning of a user-defined+
, it cannot assume that it is commutative and interpret2+aa
asaa+2
. This example is trivially handled by using nonmember functions. << |
- binary and unary operators -
- class/object construction - operator overloading
1 | basic facilities << 3 >> class derivation | 5 | 6 | 7 | 8