[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
operator operator Type
operator operator_symbol(parameters) {statements;}
The operator keyword allows you to overload (i.e. customize the
deifinition for your objects) the action of a given operator. The
operators << and >> are already overloaded in C++. The only operators
you cannot overload are:
?: . :: .* ->*
-------------------------------- Example ---------------------------------
This example overloads the + operator to work on complex numbers.
complex operator+ (complex conum1, complex conum2)
{
return complex(conum1.real+conum2.real, c1onum.imag+conum2.imag);
}
See Also: class
Online resources provided by: http://www.ClipX.Net --- NG 2 HTML conversion by Dave Pearson