+ 2

Can you give an example Of practical use Of operators overloading?

26th Mar 2016, 8:08 PM
Julio Muñoz
Julio Muñoz - avatar
3 Respostas
+ 6
It allows you to code complex manipulation with objects as simple expressions with common operators instead of member functions. It increases the readability of your code. And makes it easier use your class. Abstact example: Instead of MyClass a, b, c; a.SetValue(b.GetValue()+c.GetValue()); You can write: MyClass a, b, c; a=b+c; if you have operators = and + overloaded in MyClass. There's more benefits in operator overloading than just that.
13th Jun 2016, 12:59 PM
Igor Korablev
Igor Korablev - avatar
+ 2
For strings in C we should use strcmp to compare them because s1==s2 means u compare their addresses not their values. But in C++ we use == directly to compare that means he already used operator overloading to make it easier for us.
9th Jul 2016, 1:54 PM
Desik
Desik - avatar
+ 1
If you create a class for complex numbers, you can overload the operators +, -, *, / to make calculations between complex numbers.
10th Apr 2016, 11:21 PM
Marios Kalathas
Marios Kalathas - avatar