Hi guys, I have a problem. Maybe someone can help me. In the first example I tried to overloading operator +, all good, works fine. In the second example, doesn't work, my question is whyyy? Because I have an constructor in second example? And the function need to be friend or something like this?
Line 10: This is a setter. Why are you calling it getxxx?
Line 51: You're not changing the private class variable. You're changing the argument (to itself). It's not a good practice to name your arguments the same as your class variables.
For line 10 I don't have an ideea, for fun I guess, it's a problem ?
I made another example and this works fine.It's a major problem if I wrote weight=weight?
How is the compiler supposed to know which weight you're referring to? The argument takes precedence over the class variable. So you were assigning the argument to itself and not changing the class variable.