#include
class Circle;
class Polygon;
class Shape {
public:
virtual ~Shape(){};
virtual void ShowType() {
cout << "Shape" << endl;
}
virtual void intersect( Shape *that ) {
cout << "Shape:intersect" << endl;
}
virtual void intersect_( Circle * );
virtual void intersect_( Polygon * );
};
class Polygon : public Shape {
public:
virtual void ShowType() {
cout << "Polygon" << endl;
}
virtual void intersect_( Polygon *that ) { that->intersect( this ); }
virtual void intersect( Polygon *that ) {
cout << "Intersect Polygon with Polygon" << endl;
}
void Polygon::intersect_( Circle *that );
virtual void intersect( Shape *that ) { that->intersect_( this ); }
virtual void intersect( Circle *that ) {
cout << "Intersect Polygon with Circle" << endl;
}
};
void Shape::intersect_( Polygon * ) { }
class Circle : public Shape {
public:
virtual void ShowType() {
cout << "Circle" << endl;
}
virtual void intersect_( Circle *that ) { that->intersect( this ); }
virtual void intersect( Circle *that ) {
cout << "Intersect Circle with Circle" << endl;
}
virtual void intersect_( Polygon *that ) { that->intersect( this ); }
virtual void intersect( Polygon *that ) {
cout << "Intersect Circle with Polygon" << endl;
}
virtual void intersect( Shape *that ) { that->intersect_( this ); }
};
void Shape::intersect_( Circle * ) { }
void Polygon::intersect_( Circle *that ) { that->intersect( this ); }
int main() {
Shape *circle = new Circle;
circle->ShowType();
Shape *polygon = new Polygon;
polygon->ShowType();
circle->intersect( polygon );
circle->intersect( circle );
polygon->intersect( circle );
polygon->intersect( polygon );
return 1;
}
##```
##
c:\test>696596
Circle
Polygon
Intersect Circle with Polygon
Intersect Circle with Circle
Intersect Polygon with Circle
Intersect Polygon with Polygon
```