I didn't actually understand what is use of operator overloading? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I didn't actually understand what is use of operator overloading?

9th Jan 2017, 8:17 AM
Pratik Sharma
Pratik Sharma - avatar
2 Answers
+ 3
Operator overloading is kind of operator customization... You can write custom methods for using operator with custom data: if you define a custom class 'Thing', compilator don't know how to handle: Thing instance1; Thing instance2; Thing instance3 = instance1 + instance2; ( this is the same as the @Dean implicit example ) If you have overloaded operator +, compilater will know what to do for handle it ^^
9th Jan 2017, 9:32 AM
visph
visph - avatar
+ 2
It's syntactic sugar; rather than writing vec1.add(vec2) you get to use the more intuitive vec1+vec2
9th Jan 2017, 8:38 AM
Leon
Leon - avatar