#include using namespace std; class Circle; class Polygon; class Shape { public: virtual void intersect(Shape *that); virtual void intersect(Circle *that)=0; virtual void intersect(Polygon *that)=0; }; class Polygon : public Shape { public: virtual void intersect(Circle *that) { cout << "Intersect polygon with circle" << endl; } virtual void intersect(Polygon *that) { cout << "Intersect polygon with polygon" << endl; } }; class Circle : public Shape { public: virtual void intersect(Circle *that) { cout << "Intersect circle with circle" << endl; } virtual void intersect(Polygon *that) { cout << "Intersect circle with polygon" << endl; } }; void Shape::intersect(Shape *that) { cout << "(Determining type of second shape)" << endl; if (dynamic_cast(that)) intersect(dynamic_cast(that)); else if (dynamic_cast(that)) intersect(dynamic_cast(that)); else cout << "Not sure about this, sorry!" << endl; } int main() { Shape *shape1 = new Polygon(); Shape *shape2 = new Circle(); shape1->intersect(shape2); }