0

Hi guys, I'm trying to overload the "<<" operator but I keep getting an error that says "too many parameters"

https://code.sololearn.com/cr6929zeI3tK/?ref=app

16th May 2020, 10:06 AM
Mustafa Ahmed
2 Answers
+ 1
You didn't overload it. You *made* operator << for your class. That's because you define them as *member functions*. Because they are binary operators and member functions, they can only accept one operator. To overload <<, make them as friend function and define them outside of the class.
16th May 2020, 12:24 PM
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż - avatar
0
You forgot to add the 'friend' keyword in front of the operator>> and operator<< function declaration. Then, in the definition remove the Rectangle:: part because friend functions are not part of the actual class, they don't have access to 'this'. Also you have 1 operator<< with an incorrect signature and you're not returning anything which might result in a crash.
16th May 2020, 12:26 PM
Dennis
Dennis - avatar