#include <iostream>
using namespace std;
class Circle;
class Square;
class Triangle;
class Shape {
// ...
public:
virtual bool Check(const Shape&)const = 0;
virtual bool Check(const Circle&)const = 0;
virtual bool Check(const Square&)const = 0;
virtual bool Check(const Triangle&)const = 0;
};
class Circle : public Shape {
// ...
public:
bool Check(const Shape& s)const{return s.Check(*this);}
bool Check(const Circle&)const
{cout << "Circle & Circle\n"; return true;}
bool Check(const Square&)const
{cout << "Circle & Square\n"; return true;}
bool Check(const Triangle&)const
{cout << "Circle & Triangle\n"; return true;}
};
class Square : public Shape {
// ...
public:
bool Check(const Shape& s)const{return s.Check(*this);}
bool Check(const Circle& c)const{return c.Check(*this);}
bool Check(const Square&)const
{cout << "Square & Square\n"; return true;}
bool Check(const Triangle&)const
{cout << "Square & Triangle\n"; return true;}
};
class Triangle : public Shape {
// ...
public:
bool Check(const Shape& s)const{return s.Check(*this);}
bool Check(const Circle& c)const{return c.Check(*this);}
bool Check(const Square& s)const{return s.Check(*this);}
bool Check(const Triangle&)const
{cout << "Triangle & Triangle\n"; return true;}
};
bool intersect(const Shape& s,const Shape& t)
{return s.Check(t);}
int main()
{
Circle c;
Square s;
Triangle t;
intersect(c,s);
intersect(t,c);
}
|