0

Operator overloading for a class

Hello AFAIK, there are few operatiors which can only be overloaded as member function and few can overloaded without member function... would like to explore this topic in detail with good explanation... can anyone help me to explain the same or share good link to go through? Thanks and Regards Ketan

18th Jul 2018, 9:16 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Respostas
+ 2
anyone to throw some light on this?? Let me describe some more detail... I/o operators can only be overloaded as friend function and it's not possible to overload as member function... Why?? because overloaded member function must have left operand as class object, but overloaded o operator must have return type as ofstream copy object... This ensures proper behaviour with cout... Same way, assignment operatior can be only overloaded as member function and not possible as friend function... Any logic for this ????????
19th Jul 2018, 5:16 PM
Ketan Lalcheta
Ketan Lalcheta - avatar