#include using namespace std; class SomeDataT { public: SomeDataT() { cout << "Constructor called " << endl; } ~SomeDataT() { cout << "Destructor called " << endl; } void Data(int newData) { data = newData; } int Data() const { return data; } SomeDataT operator ++(int) { SomeDataT originalValue{*this}; ++data; return originalValue; } SomeDataT & operator ++() { ++data; return *this; } private: int data{4}; }; ostream & operator << (ostream & s, const SomeDataT & other); SomeDataT & GoodFunction(SomeDataT & other); SomeDataT & BadFunction(SomeDataT other); int main() { SomeDataT data; data.Data(44); cout << "The data is "; cout << data << endl; cout << endl; int i{10}; int j; j = i; cout << "i = " << i << " j = " << j << endl; cout << endl; cout << "j = ++i" << endl; j = ++i; cout << "i = " << i << " j = " << j << endl; cout << endl; cout << "j = i++" << endl; j = i++; cout << "i = " << i << " j = " << j << endl; cout << endl; cout << "The same for our class " << endl; SomeDataT copy{data}; cout << "data = " << data << " copy = " << copy << endl; cout << endl; cout << "copy = ++data" << endl; copy = ++data; cout << "data = " << data << " copy = " << copy << endl; cout << endl; cout << "copy = data++" << endl; copy = data++; cout << "data = " << data << " copy = " << copy << endl; cout << endl; return 0; } ostream & operator << (ostream & s, const SomeDataT & other){ s << other.Data(); return s; } SomeDataT & GoodFunction(SomeDataT & other){ return other; } /* SomeDataT & BadFunction(SomeDataT other){ return other; } */