I. Overloading rules
I. Operators that can be overloaded
+ |
- |
* |
/ |
% |
^ |
& |
| |
~ |
! |
= |
> |
< |
+= |
-= |
*= |
/= |
%= |
^= |
&= |
|= |
>> |
<< |
>>= |
<<= |
== |
!= |
>= |
<= |
&& |
|| |
++ |
-- |
->* |
, |
- |
[] |
() |
operator NEW |
Operator New[] |
operator delete |
operator delete [] |
Ii. operators that cannot be overloaded
:: |
. |
.* |
? : |
sizeof |
typeID |
New |
Delete |
Static_cast |
dynamic_cast |
Const_cast |
Reinterpret_cast |
III. Basic Rules
1. The unary operator can be a member function without parameters [1] or a non-member function with one parameter [1].
2. The two-dollar operator can be a member function with one parameter [1] or a non-member function with two arguments [1].
3.operator=, operator[], operator (), operator-> can only be defined as member functions [1].
The return value of the 4.operator-> must be a pointer or an object that can be used.
5. Overloads operator++ and operator--with an int parameter representing the suffix, prefixed with no parameters.
6. In addition to operator new AND operator Delete, there must be at least one non-built-in data type in the overloaded operator parameter.
[email protected] The search scope is: X member function---Global function/x function in the namespace function/y The friend of the/x in the name space
The friend function of number/y.
8. Overloaded operators should try to simulate the behavior of the operator's built-in type.
C + + Operator overloading