+ 2
Why use Operator overloading ?
I can't understand why we should use operator overloading function and where we use it in program , is it necessary ?
4 odpowiedzi
+ 6
If default working of operator doesn't satisify you can override it for your own purpose. For example if you created Car object and it has float cost member. You can override (+) operator for this class, so if you add two cars actually their costs are added.
+ 3
For example if you code a class and want to add or multiply two objects of that class. Then you need a function for the right way of adding/multiplying them.
Think of matrix multiplication, where the standard * for single numbers does not work. Thus the operator * has to be overloaded to provide the correct result when multiplying two matrices.
+ 1
to give additionalfunction so we use