This post will introduce how to overload different operators in C++ language.
Some important operators
- input and output operators:
<<,>>. - assignment operator:
=. - subscript operator:
[]. - pre- and post- increament operator:
++,--. - call operator:
().
|
|
Dereference operator
- Arrow operator
->:- Example:
a->b. - If
ais a pointer pointing to an object has memberb, then returnb. - If
ais an object that has overloaded->operator, then calloperator ->(). When this return a pointer then run as above.
- Example:
|
|
- Derecerence operator:
*
|
|