// polygon4.cc #include #include using namespace std; class Polygon { public: int NumSides; void Draw(void) { cout << "Drawing polygon with " << NumSides << " sides." << endl; } Polygon(int sides) { NumSides = sides; cout << "In Polygon constructor with " << NumSides << " sides" << endl; } }; class Triangle: private Polygon { public: Triangle(): Polygon(3) { // Call base class constructor with required args cout << "In Triangle constructor" << endl; } }; int main() { Triangle MyTriangle; Polygon MyPentagon(5); // MyTriangle.NumSides = 4; // won't work if we uncomment this // MyTriangle.Draw(); // this won't work either! // MyPentagon.Draw(); // or this! }