// z6.3.2-delete.cc // #include #include using namespace std; class Point { public: double x, y; string name; Point(string w, double xx, double yy) { cout << "constructor: " << w << endl; name = w; x = xx; y = yy; } ~Point() { cout << "destructor: " << name << endl; } void print() { cout << name << ": (" << x << "," << y << ")" << endl; } }; int main() { Point p1("p1",1,2); p1.print(); { Point p2("p2",2,3); p2.print(); } Point *p3 = new Point("p3",3,4); (*p3).print(); p3->print(); delete p3; // without this, p3 destructor would never be called }