- 2068 Baisakh · 2 marks
Overloadable operators in C++
Short answer
Most operators can be overloaded: arithmetic (+, -, *, /, %), unary (++, --, !, -), relational (==, <, >, <=, >=, !=), logical (&&, ||, !), bitwise (&, |, ^, ~, <<, >>), assignment (=, +=, etc.), subscript ([]), function call (()), member access (->, ->*), comma, address-of, and memory (new, delete). Not overloadable: :: . .* ?: sizeof typeid.
What are the overloadable operators in C++?
C++ allows most of its operators to be overloaded for user-defined types.
| Category | Operators |
|---|---|
| Arithmetic | + - * / % |
| Unary | + - ++ -- ! ~ |
| Relational | == != < > <= >= |
| Logical | && || ! |
| Bitwise | & | ^ ~ << >> |
| Assignment | = += -= *= /= %= &= |= ^= <<= >>= |
| Subscript, call, pointer | [] () -> ->* |
| Address, comma | & , |
| Memory | new delete new[] delete[] |
Notes:
=,[],()and->must be overloaded as member functions.- Operators like
<<and>>for streams are overloaded as non-member (friend) functions. - Operators
:: . .* ?: sizeof typeidcannot be overloaded.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Operators that cannot be overloaded · Object Oriented Programming, chapter 5 · asked 2×