I am practicing my OOP and I have the following classes: Point and Circle. Specifically, Circle has a center Point, and a radius. Here is the relevant code:
In trying to construct Circle, you tried to construct a Point using a default constructor:
Circle::Circle(const Point& center, double radius)
^
//...Calling default constructor...
...and then assigned it a value:
center_pt = center;
Given that the default constructor didn't exist, you got the compile-time error.
Two solutions are:
1) Construct a Point using a member initialisation list:
Circle::Circle(const Point& center, double radius): center_pt(center),
radius_size(radius) {
}
2) Define a default constructor for Point:
Point::Point(){
}
I am primarily answering this question to place emphasis on option 2 as I believe this emphasis was lacking in the answers above. Sometimes, it is more practical to default construct an object in a givens class parameter list and assign it a value at a later stage. This is encountered a bit in GUI programming in using the Qt framework.