Not exactly, I was just thinking more along the line of "a Circle has-a (center) Point", rather than "a Circle is-a Point".
If it's an exercise in inheritance, that wouldn't be much different.
What I think was a key issue with your earlier attempts was the distance function.Code:class Circle : public Point
{
double radius;
public:
Circle(double radius_, double x_ = 0, double y_ = 0)
: Point(x_, y_), radius(radius_)
{
}
double area()
{
return PI * radius * radius;
}
};
Code:class Point
{
double x, y;
public:
Point(double x_ = 0, double y_ = 0) : x(x_), y(y_)
{
}
friend double distance(const Point& pt1, const Point& pt2)
{
double a = pt2.x - pt1.x, b = pt2.y - pt1.y;
return std::sqrt(a * a + b * b);
}
};