582 views

Which of the following operators cannot be overloaded in $\textsf{C/C++}$ ?

1. Bitwise right shift assignment
3. Indirection
4. Structure reference

### Operators which cannot be overloaded

Most can be overloaded. The only C operators that can’t be are . and ?: (and sizeof, which is technically an operator). C++ adds a few of its own operators, most of which can be overloaded except :: and .*.

There is no fundamental reason to disallow the overloading of ?:. So far the committee just hasn’t seen the need to introduce the special case of overloading a ternary operator. Note that a function overloading would not be able to guarantee that only one of expr2 and expr3 was executed.

sizeof cannot be overloaded because built-in operations, such as incrementing a pointer into an array implicitly depends on it.

1
1,822 views
2
3