// pointers to base class // One of the key features of derived classes is that a pointer to a derived class // is type-compatible with a pointer to its base class. Polymorphism is the art of // taking advantage of this simple but powerful and versatile feature, that brings // Object Oriented Methodologies to its full potential. #include using namespace std; class Polygon { protected: int width, height; public: void set_values (int a, int b) { width=a; height=b; } }; class Rectangle: public Polygon { public: int area () { return (width * height); } }; class Triangle: public Polygon { public: int area () { return (width * height / 2); } }; int main () { Rectangle rect; Triangle trgl; Polygon *poly1 = ▭ Polygon *poly2 = &trgl; poly1->set_values (4,5); poly2->set_values (4,5); cout << "The area of the rectangle is " << rect.area() << endl; cout << "The area of the triangle is " << trgl.area() << endl; getchar(); return 0; }