#include #include #include #include using namespace std; class Point { double* x; double* y; public: double* getX() const { return x; } double* getY() const { return y; } void set(double,double); void set(const string& arg); void print() const; void release() { delete x; x = nullptr; delete y; y = nullptr; cout << "dynamic memory released\n"; } }; void Point::set(double arg1,double arg2) { x = new double(arg1); y = new double(arg2); } void Point::set(const string& arg) { set(stod(arg.substr(0,6)),stod(arg.substr(8))); } void Point::print() const { cout << '(' << *x << ',' << *y << ')' << endl; } int main() { Point p; p.set(4.5,6.7); p.print(); p.release(); /* const string fn("data.txt"); Point points[24]; ifstream fin(fn); if (!fin) { cerr << "can't open " << fn << endl; exit(1); } string buffer; for (int i = 0; i < 24; i++) { getline(fin,buffer); points[i].set(buffer); } for (int i = 0; i < 24; i++) { points[i].print(); points[i].release(); } */ }