I'm working with two classes (pointType and circleType). Right now, I'm just testing to make sure the functions work properly and it appears something is wrong with the setPoint function and maybe the print function as well.
#include <iostream>
#include "pointType.h"
#include "circleType.h"
usingnamespace std;
int main()
{
circleType circle;
double radius, xCoord, yCoord;
cout << "Enter the X and Y coordinates for the center of the circle." << endl;
cin >> xCoord >> yCoord;
circle.setPoint(xCoord, yCoord);
circle.print();
return 0;
}
I was just in a huge debate on the style of these kinds of classes. I said that this type of design (with a bunch of useless getters/setters) was terrible, but other people disagreed.
I'm not saying you should change your code, but if you are interested in the discussion, here is a link to it:
@Disch: unless you want to use immutable point and circle classes, these classes are perfect candidates for getters and setters. They don't control themselves, they just maintain their state for you. They're utility classes.
You're probably right, but I was given the two header files and told to define and implement them. Thank you for the suggestions. I'm still pretty new to this an I appreciate all the feedback :)
Also note that Circle should not inherit from Point. Inheritance implies a "IS A" relationship: a Circle is not a point. More formally it violates the Liscov Substitution Principle (Google that). I learnt that from ne555.
Instead, Circle should have a member variable that is of type Point. This is a "HAS A" type relationship an is also known as aggregation.
The other type of relationship is "USES A", that happens when an object of a particular type is passed as a parameter to to a function.
I agree with Disch about the unnecessary getters / setters. Getters may not be so bad, but public setters mean that everything may as well be public !! This is a common problem for beginners, and is improved with knowledge about initialisation lists in constructors.
Note that the Boost library stores a point as a vector, which is a private member variable. I learnt that from Cubbi.
@Disch: unless you want to use immutable point and circle classes, these classes are perfect candidates for getters and setters. They don't control themselves, they just maintain their state for you. They're utility classes.
I'm not going to get into it again. I'll just say that I'm very happy that every point/vector class I've ever used had public x/y/z members.
Have fun debugging mysterious NaN and INF values in your vectors :)
You're mistreating the problem. If NaN/INF are a problem, they're going to be a problem everywhere... not just in your vectors. So why butcher the vector class to address a problem that isn't with the vector class?
If you don't want NaN/INF, then don't use doubles.
1 2 3 4 5 6 7 8 9
class NotQuiteADouble
{
// a class the behaves like a double, but does not allow NaN/INF
};
sf::Vector<NotQuiteADouble> foo;
foo.x = 5.0; // yay! public! No risk of NaN!