Which of the following operators cannot be overloaded in C/C++ ?
2017
Which of the following operators cannot be overloaded in C/C++ ?
- A.
Bitwise right shift assignment
- B.
Address of
- C.
Indirection
- D.
Structure reference
Attempted by 121 students.
Show answer & explanation
Correct answer: D
Answer: Structure reference (the member access operator '.') cannot be overloaded in C++.
Why: The C++ language forbids overloading the built-in member access operator '.' because it would break name lookup rules and object model assumptions. As an alternative for pointer-like behavior you can overload operator->. Other operators that cannot be overloaded include the scope resolution operator '::', the conditional operator '?:', and sizeof.
Bitwise right shift assignment (>>=): Can be overloaded for user-defined types; typically implemented as operator>>=(...) (often as a member).
Address of (&): Can be overloaded by defining operator& for a class to customize address-taking behavior.
Indirection (*): Can be overloaded by defining operator*; commonly used for iterator-like or smart pointer types.
Structure reference (.): Cannot be overloaded. Use operator-> to provide custom member access behavior for pointer-like classes.