|
Operators you can’t overload
There are certain operators in the
available set that cannot be overloaded. The general reason for the restriction
is safety. If these operators were overloadable, it would somehow jeopardize or
break safety mechanisms, make things harder, or confuse existing
practice.
- The member selection
operator.. Currently, the dot has a meaning for any member in a class,
but if you allow it to be overloaded, then you couldn’t access members in
the normal way; instead you’d have to use a pointer and the arrow
operator->.
- The
pointer to member dereference operator.*, for the same reason as
operator..
- There’s
no exponentiation operator. The
most popular choice for this was operator** from Fortran, but this raised
difficult parsing questions. Also, C has no exponentiation operator, so C++
didn’t seem to need one either because you can always perform a function
call. An exponentiation operator would add a convenient notation, but no new
language functionality to account for the added complexity of the
compiler.
- There are
no user-defined operators. That is, you can’t make
up new operators that aren’t currently in the set. Part of the problem is
how to determine precedence, and part of the problem is an insufficient need to
account for the necessary
trouble.
- You
can’t change the precedence rules. They’re hard enough to remember
as it is without letting people play with
|
|