RAD Studio |  |

Overloading Operators
See Also
Collapse All

C++ lets you redefine the actions of most operators, so that they perform specified functions when used with objects of a particular class. As with overloaded C++ functions in general, the compiler distinguishes the different functions by noting the context of the call: the number and types of the arguments or operands.

All the operators can be overloaded except for:

Copy Code

    .   .*   ::   ?:

The following preprocessing symbols cannot be overloaded.

Copy Code

     #   ##

The =, [ ], ( ), and -> operators can be overloaded only as nonstatic member functions. These operators cannot be overloaded for enum types. Any attempt to overload a global version of these operators results in a compile-time error.

The keyword operator followed by the operator symbol is called the operator function name; it is used like a normal function name when defining the new (overloaded) action for the operator.

A function operator called with arguments behaves like an operator working on its operands in an expression. The operator function cannot alter the number of arguments or the precedence and associativity rules applying to normal operator use.

See Also

Example Of Overloading Operators

Overloaded Operators And Inheritance

Overloading Binary Operators

Overloading Operator Functions

Overloading The Assignment Operator =

Overloading The Class Member Access Operators ->

Overloading The Function Call Operator ( )

Overloading The Subscript Operator []

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!