I also have an overloaded constructor as well-is it necessary to put it at the top of the code with the default constructor? |
From a syntax perspective, no. The code can go anywhere in the .cpp file. From a style perspective, sometimes its nice to have functions in the .cpp file in the same order as they are declared in the header file. I usually put all my constructors at the top of the .cpp file.
Also do I need to use const with the get functions? I wasn't sure. |
It would make sense to make the function const (
int getX() const;
). This will allow you to get the value out of a const Point object if you need to because the get function does not modify the object.
Do I need to call checkRange for the read function? I feel like the function isn't doing anything if I never call it. But if I called it should I use an if statement? |
The checkRange function is supposed to return a value. Use it. BTW, line 49 is messed up. You only need to check if
val < 0
.
So apparently I need to call the checkRange function before each set/get. |
Why would you need to call checkRange before a get?
Your earlier question was about the read function. Do you think that is a set function? I think it is.
You want to call checkRange any time you are about to set an X or Y value because you want to make sure your data is always valid. Once it's valid, you can be sure that your writes and gets give you valid output.
Or do I need to call the function using point because it's in the class? |
There is no
point
. You could use this-> if you wanted to, but I don't think you've learned about that yet. So, no, you can just use
x
like you have. But I would suggest you replace lines 3 - 5 with simply
x = checkRange(xVal);