- Asked 2/10
- 2072 Chaitra · 2 marks
- 2068 Chaitra · 2 marks
Operators that cannot be overloaded
Short answer
Operators that cannot be overloaded are :: (scope resolution), . (member access), .* (pointer-to-member), ?: (ternary), sizeof, and typeid. These operate on names or types, not values, and overloading would compromise language safety.
What are the non-overloadable operators in C++?
Most C++ operators can be overloaded, but the following cannot be overloaded:
| Operator | Name |
|---|---|
:: | Scope resolution operator |
. | Member access (dot) operator |
.* | Pointer-to-member operator |
?: | Conditional (ternary) operator |
sizeof | Size-of operator |
typeid | Run-time type information operator |
The cast operators const_cast, dynamic_cast, static_cast and reinterpret_cast, and the preprocessor symbols # and ##, also cannot be overloaded.
Reason: these operators work on names or types (not values), or their meaning is fixed by the language, so changing them could make the language unsafe or ambiguous. Also, the precedence, associativity and number of operands of an operator cannot be changed by overloading, and new operator symbols cannot be created.
Note: =, [], () and -> can be overloaded, but only as member functions.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Overloadable operators in C++ · Object Oriented Programming, chapter 5