Operator Overloading

Operators in C++ can be overloaded similar to functions. The overloaded operator does not lose any of its original functionalities . Relational and logical operators can also be overloaded .

 

Restrictions to overloaded operators that can't be changed:

  1. Precedence

  2. Number of operands

All C++ operators can be overloaded except the :

  1. . (dot)

  2. ::

  3. .*

  4. ?

Overloaded operators can be inherited except for the =.

 

NOTE : You can change the + operator to perform output , but that would confuse the users.

 

The syntax of a member operator function:

     Return-type  class-name :: operator#(arg-list)

              {

                  // operation to be performed

              }