Operator Overloading in C++, Do you remember ?

Operator overloading is one of the most useful feature of C++. I personally feel every OOP language should provide this feature.

When it comes to remember which of the operators not allowed to be overloaded. Whats your answer ?

Google it and you will get some links :

And for programmers who prepare for interviews online :)

They all just list the operators. @Bjarne Stroustrup has given logic behind them. But the problem remains the same. How would you remember ? You are on a beach, relaxing and writing some C++ code but no internet.

I was also struggling then I deviced a formula :)

‘Any operator which has “dot” in it — except NOT “!”’ can not be overloaded.

So lets go through all of them :

. (Member Access or Dot operator)
?: (Ternary or Conditional Operator )
:: (Scope Resolution Operator)
.* (Pointer-to-member Operator )
sizeof (Object size Operator)
typeid (Object type Operator)

Lets apply our formula. Every operator has a dot ‘.’ in it. Even if you observe last two. sizeof and typeid also have a dot in the form of ‘i’

There was one exception though which is NOT ‘!’

Did you like the formula :)