#include #include #include "Rectangle.hpp" using namespace std; Rectangle::Rectangle() { width_ptr = new (nothrow) int; height_ptr = new (nothrow) int; if(width_ptr == NULL || height_ptr == NULL) { cerr << "Memory allocation failure!\n"; exit(-1); } *width_ptr = *height_ptr = 0; cout << "Calling 0 args constructor" << endl; } Rectangle::Rectangle(int w, int h) : Rectangle() { *width_ptr = w; *height_ptr = h; cout << "Calling 2 args constructor" << endl; } Rectangle::Rectangle(int s) : Rectangle(s,s) { cout << "Calling 1 args constructor" << endl; } Rectangle::~Rectangle() { cout << "Destructing rectangle (w:"<< *width_ptr <<", h:"<<*height_ptr<<")\n"; delete width_ptr; delete height_ptr; } void Rectangle::setWidth(int w) { *width_ptr = w; } void Rectangle::setHeight(int h) { *height_ptr = h; } int Rectangle::getWidth() { return *width_ptr; } int Rectangle::getHeight() { return *height_ptr; } int Rectangle::getArea() { return *width_ptr * *height_ptr; }