// polygon9.cc #include #include using namespace std; class Polygon { public: int NumSides; Polygon(int sides) { cout << "Creating a Polygon" << endl; NumSides = sides; } ~Polygon() { cout << "Destroyed Polygon" << endl; } }; class Triangle: public Polygon { public: Triangle(): Polygon(3) { cout << "Creating a Triangle" << endl; } ~Triangle() { cout << "Destroyed Triangle" << endl; } }; void DeletePolygon(Polygon* poly) { delete poly; } int main() { cout << "About to create a Triangle on the heap" << endl; Triangle* pTriangle = new Triangle; cout << "About to destroy the Triangle on the heap" << endl; DeletePolygon(pTriangle); cout << "About to create a Triangle on the stack" << endl; Triangle MyTriangle; cout << "Triangle on stack about to go out of scope" << endl; return 0; }