+ 1
Can someone explain the basics of operator-overloading for me?
I am making a program that would be nice with it. Can someone give me an example and explain how it works? It would be so helpful, thank you ^^
2 Antworten
+ 3
Operator Overloading
--------------------------------------------------------------------------------------------
- This helps in redefining operator with respect to the object
- Almost all operators can overloaded except - ., ::, :, ?, ->
<return-type> operator <sym> (parameter);
For example please visit
https://code.sololearn.com/cKpSHlLsr1Ih/#cpp
0
operator overloading is done to use one operator in a sense for which it was defined.
eg.
void operator + (obj a, obj b)
{
obj c;
c.q=a.q+b.q;
printf("addition of two objects : %d",c q);
}
here + was originally defined for adding two numerals, but here is redefined to add two objects.