I have a simple program that determines the radius, area, and circumference of a circle. I want to have three constructors: the default constructor should sets the default values, the first overloaded constructor sets a value for radius, and the second overloaded constructor sets a value for the center of the circle.
However, at definition I would like to define a circle's radius AND its center by calling its constructors. When I try to do something like this:
1 2
Circles sphere(8);
Circles sphere(9,10);
I get a compiler error that makes sense: "error: redefinition of 'sphere'".
So how can I define attributes using two different constructors at object definition?
Here is my code (many functions left out as they are not relevant:
In main you have to match the number of arguments in the constructor to main. if you say Circles(int, int) then you need to provide the arguments in main.
These lines define two separate objects with the same name (illegal).
If you want to set all the members from a single constructor call, write one that takes all the parameters needed to set them, public Circles(float r, int x, int y);
Data doesn't have to be set from the ctor. void Circles::SetCenter(int x, int y)... is perfectly fine.