// polygon6a.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 MyTriangle.Polygon::Draw("Hi"); // now this will work }