why we need operator overloading or overriding?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

why we need operator overloading or overriding??

why we need this operator?

16th Jun 2018, 7:47 AM
Rahul kumar
3 Answers
+ 2
You don't need to use operator overloading, but it can make code easier to understand. Foe example: x = a + b; is the same thing as calling: x = a.plus(b); In the plus method, if you want to access the entire class a, you would use this. The instance based methods are implement hidden from view as if coded like: class plus(class this, class other) {} You also need to use this to access the properties or methods hidden by locally defined names. Of course, you may always use this for your access.
16th Jun 2018, 6:55 PM
John Wells
John Wells - avatar
0
template<class T> void foo(T a, T b) { if (a < b) doSomething(); else doSomethingElse(); }
16th Jun 2018, 7:56 AM
Vlad Serbu
Vlad Serbu - avatar
0
operator overloading is useful when you have classes for example and you want to be able to use them as operands for performing specific things. it's not used too often, but when it is, boy does it come in handy!
16th Jun 2018, 1:19 PM
hinanawi
hinanawi - avatar