// polygon6b.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; } void Draw(string message) { // happy with base class method, just call it! Polygon::Draw(message); } }; int main() { Triangle MyTriangle; Polygon MyPentagon(5); MyPentagon.Draw("Hello"); // uses generic Polygon::Draw() routine MyTriangle.Draw("Hi"); // simpler syntax here now }