// polygon2.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; } }; class Square: public Polygon { public: Square() { NumSides = 4; } // the above constructor won't work b/c there isn't a corresponding // default constructor for the base class, Polygon }; class Triangle: public Polygon { public: Triangle() { NumSides = 3; } // the above constructor won't work b/c there isn't a corresponding // default constructor for the base class, Polygon }; int main() { Triangle MyTriangle; Square MySquare; Polygon MyPentagon(5); MyTriangle.Draw(); MySquare.Draw(); MyPentagon.Draw(); }