#include using namespace std; class Sample { public: int* p; Sample(int a = 1){ cout << "Default constructor" << endl; p = new int(a); //request new memory } Sample(Sample& input) //copy constructor { p = new int(*input.p); cout << "Copy " << p << " <== " << input.p << endl; } Sample & operator = (Sample & input) //assignment constructor { cout << "Assign " << p << " <== " << input.p << endl; *p = *(input.p); return *this; } friend Sample operator ++ (Sample& input, int); ~Sample() { cout << "~~~ Destructor called ~~~" << endl; delete p; } }; Sample operator ++ (Sample& input, int) { Sample temp = input; *(input.p) ++; return temp; } int main() { Sample ex1(10); Sample ex2; ex2 = ex1++; cout << "value ex1 " << *(ex1.p) << endl; cout << "value ex2 " << *(ex2.p) << endl; }