0
why we need operator overloading or overriding??
why we need this operator?
3 Respostas
+ 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.
0
template<class T> void foo(T a, T b)
{
if (a < b)
doSomething();
else
doSomethingElse();
}
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!