// polygon3d.cc #include #include using namespace std; class Polygon { protected: int NumSides; // outsiders shouldn't be able to change this // but perhaps derived classes should be able to access it 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 Triangle: public Polygon { public: Triangle(): Polygon(3) { // Call base class constructor with required args cout << "In Triangle constructor" << endl; } void Report(void) { cout << "I'm a triangle, I have " << NumSides << " sides." << endl; } }; class RightTriangle: public Triangle { public: RightTriangle(): Triangle() { cout << "In RightTriangle constructor" << endl; } void Report(void) { cout << "I'm a right triangle, I have " << NumSides << " sides." << endl; } }; int main() { RightTriangle MyRightTriangle; MyRightTriangle.Report(); }