// polygon3a.cc #include #include using namespace std; class Polygon { private: int NumSides; // outsiders shouldn't be able to change this public: void Draw(void) { cout << "Drawing polygon with " << NumSides << " sides." << endl; } Polygon(int sides) { NumSides = sides; cout << "In Polygon constructor with " << NumSides << " sides" << endl; } }; class Square: public Polygon { public: Square(): Polygon(4) { // Call base class constructor with required args cout << "In Square constructor" << endl; } }; class Triangle: public 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; // Now we can't do this...good! MyTriangle.Draw(); MyPentagon.Draw(); }