Which operator cannot be overloaded in C++ and why?

In C++, some operators cannot be overloaded because they have a special meaning in the language.

The following operators cannot be overloaded:

Operators

  1. . (member selection operator)
  2. .* (pointer-to-member selection operator)
  3. :: (scope resolution operator)
  4. ? : (ternary operator)
  5. sizeof
  6. typeid
  7. const_cast
  8. static_cast
  9. dynamic_cast
  10. reinterpret_cast

Reason

These operators cannot be overloaded because they are part of the core syntax of the language and their behavior is tightly defined. Overloading these operators would change the basic meaning of the language and could lead to unexpected behavior and bugs.

kabeer

Added  Feb 02, 03:09 am

Article tags

C++
×
SignUp with Email
X