ostream & operator << (ostream & s, const SomeDataT & other){ s << other.Data(); return s; } ... SomeDataT data; ... cout << data;
cout
and to data
cout
The code: 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; produces i = 10 j = 10 j = ++i i = 11 j = 11
i = 11; cout << "j = ++i" << endl; j = ++i; cout << "i = " << i << " j = " << j << endl; produces j = i++ i = 12 j = 11
SomeDataT & operator ++(); SomeDataT operator ++(int);
this
this
is a member of every class.
SomeDataT operator ++(int) { SomeDataT originalValue{*this}; ++data; return originalValue; } SomeDataT & operator ++() { ++data; return *this; }
SomeDataT & GoodFunction(SomeDataT & other){ return other; } SomeDataT & BadFunction(SomeDataT other){ return other; }