#include using namespace std; // Definition of Class Base class Base { private: int a; int b; public: void SetA(int i) {a = i; return;}; int GetA() {return a;}; void SetB(int i) {b = i; return;}; int GetB() {return b;}; void Prints() {cout << "Base " << a << " " << b << endl; return;}; Base(int i , int j) { cout << "allocating Base " << this << " " << i << " " << j << endl; a = i; b = j; return;}; Base(Base & base) { cout << "copy constructor B " << this << " " << endl; base.Prints(); *this = base;} ~Base() {cout << "deallocating Base " << this << endl;}; }; class Derived : public Base { private: int c; int d; public: void SetC(int i) {c = i; return;}; int GetC() {return c;}; void SetD(int i) {d = i; return;}; int GetD() {return d;}; void Prints() {cout << "Derived " << c << " " << d << " AND " ; Base::Prints(); return;}; Derived(int i, int j) : Base (i+2, j+2) { cout << "allocating Derived " << this << endl; c = i; d = j; return;}; Derived(Base base, int i, int j) : Base (base) { cout << "allocating Derived " << this << endl; c = i; d = j; return;}; Derived(Derived & der): Base(der) { cout << "copy constructor D " << this << " " << endl; der.Prints(); *this = der;} ~Derived() {cout << "deallocating Derived " << this << endl;}; }; int main() { cout << endl; int i = 1; int j = 2; Base x (i,j); x.Prints(); Derived y (i,j); y.Prints(); Base h (i+2,j+2); h.Prints(); Derived w (h,i+4,j+4); w.Prints(); h.Prints(); }