|
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:
Precedence
Number of operands
All C++ operators can be overloaded except the :
. (dot)
::
.*
?
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
}