#include <stdio.h>
struct point
{
double x, y;
};
class circle
{
friend bool operator==
(point const &this_, circle const &that)
{
return that == this_;
}
friend bool operator!=
(point const &this_, circle const &that)
{
return that != this_;
}
public:
circle(double const x, double const y,
double const radius = 1)
{
center_.x = x;
center_.y = y;
radius_ = radius;
}
circle(point const ¢er,
double const radius = 1)
{
this->circle::circle(center.x, center.y, radius);
}
bool operator==(circle const &that) const
{
return center_.x == that.center_.x &&
center_.y == that.center_.y &&
radius_ == that.radius_;
}
bool operator!=(circle const &that) const
{
return !(*this == that);
}
operator point const &() const
{
return center_;
}
private:
point center_;
double radius_;
};
#define TEST(condition) \
printf("%s %s\n", #condition, \
((condition) ? "true" : "false"));
int main()
{
point p = {3, 2};
circle c(3, 2);
TEST(p == c)
TEST(p != c)
TEST(c == p)
TEST(c != p)
return 0;
}
End of Listing