// polygon6.cc #include #include using namespace std; class Polygon { public: int NumSides; void Draw(void) { cout << "Drawing polygon with " << NumSides << " sides." << endl; } void Draw(string message) { cout << "Drawing polygon with " << NumSides << " sides" << endl; cout << "and writing " << message << " inside" << endl; } Polygon(int sides) { NumSides = sides; } }; class Triangle: public Polygon { public: Triangle(): Polygon(3) { // Call base class constructor with required args } void Draw(void) { // This routine overrides the base class Draw() routine cout << "Using special triangle drawing routine" << endl; } }; int main() { Triangle MyTriangle; Polygon MyPentagon(5); MyPentagon.Draw("Hello"); // uses generic Polygon::Draw() routine // following line won't work because we overrode Draw(void) // and this hides all other forms of Draw() in base class from derived class MyTriangle.Draw("Hi"); }