Overloading operators

You can overload operators for classes created in IBM® Rational® Rhapsody®. For example, for a Stack class, you can overload the "+" operator to automatically perform a push() operation, and the "‑" operator to automatically perform a pop() operation.

About this task

All the overloaded operators (such as operator+ and operator-) can be modeled as member functions, except for the stream output operator<<, which is a global function rather than a member function and must be declared a friend function. The overloaded operators that are class members are all defined as primitive operations.

To illustrate operator overloading, consider two classes, Complex and MainClass, defined as follows:


Feedback