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 :
These are questions about C++ Style and Technique that people ask me often. If you have better questions or comments on…www.stroustrup.com
And for programmers who prepare for interviews online :)
In C++, following operators can not be overloaded: . (Member Access or Dot operator) ?: (Ternary or Conditional…www.geeksforgeeks.org
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 :
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 :)