devxlogo

Restrictions on Operator Overloading

Restrictions on Operator Overloading

The following restrictions apply to operator overloading:

1. Invention of new operators is not allowed. For example:

 void operator @ (int) ; //illegal, @ is not a built-in operator or a type name

2. Neither the precedence nor the number of arguments of an operator may be altered. An overloaded && for example, must have exactly two arguments–just like the built-in && operator.

3. The following operators cannot be overloaded:

 Direct member access operator 				. De-reference pointer to class member operator 		.*Scope resolution operator				::Conditional operator					?:Sizeof operator						sizeof

Similarly, any of the new casting operators: static_cast<>, dynamic_cast<>, reinterpret_cast<> and const_cast<>, as well as the # and ## preprocessor tokens, may not be overloaded.

See also  How to Create and Deploy QR Codes Online: A Comprehensive Guide
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist