#include #include using namespace std; class Rectangle { private: int *width, *height; public: Rectangle(int w, int h); ~Rectangle(); void setWidth(int w); void setHeight(int h); int getWidth(); int getHeight(); }; Rectangle::Rectangle(int w, int h) { width = new (nothrow) int; height = new (nothrow) int; if(width == NULL || height == NULL) { cerr << "Memory allocation failure!\n"; exit(-1); } *width = w; *height = h; cout << "Constructing rectangle (w:"<< *width <<", h:"<<*height<<")\n"; } Rectangle::~Rectangle() { cout << "Destructing rectangle (w:"<< *width <<", h:"<<*height<<")\n"; delete width; delete height; } void Rectangle::setWidth(int w) { *width = w; } void Rectangle::setHeight(int h) { *height = h; } int Rectangle::getWidth() { return *width; } int Rectangle::getHeight() { return *height; } int main () { Rectangle rect(5,6); cout << "area: " << rect.getWidth() * rect.getHeight() << endl; return 0; }