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
a
is a pointer pointing to an object has memberb
, then returnb
. - If
a
is an object that has overloaded->
operator, then calloperator ->()
. When this return a pointer then run as above.
- Example:
|
|
- Derecerence operator:
*
|
|