That's my third lesson of classes and I am having trouble with my HW,
I've to create an object with 2 properties and the object has to return addition, subtraction, division and multiplication.
Any recommendation or reference will be recognized !
"this->" is not needed in this context as the public member functions already have access to "x" and "y". It does have its use on occasion, but if you feel it is needed here it should not make any difference.
The set functions generally are written as:
1 2 3 4
void setXm(int value)
{
x = value;
}
Then you would use A.setXm(10);.
My first thoughts until I have a cchance to go over it more.
the combined assignment operators modify the values.
x*=y changes x, in other words... so after you do the first one, x and y have changed and your results will not be what you expected.
this ties in with the above post, but may explain what is going on if you are seeing odd results.
line 17 is odd. Yes, null is really just zero, but it is only really supposed to be used with pointers, and you have no pointers (and c++ has moved to nullptr, leaving null for C code).
on the 'this' thing:
void setYa(int y){ this->y=y;} //this is necessary here, because you need to say which y you need in which place.
void setYa(int input){ y= input;} //if you use any other name than y, you don't need the this clutter.
I recommend in all code, whether in classes or not, to avoid having the same or even very similar variable names (with a few exceptions like for loop scope variables). The more code you have in a project, the more difficult it becomes to spot errors about which copy of the same name you meant to be using or which variable you wanted when there are several with similar names. Again use common sense on exceptions to this ... we had constants with names like OOOI OOIO OOII set of 'binary' codes in an embedded project once :P