//cat.cpp -- by tsaiwn // test default constructor, copy constructor, assignment operator, // and operator overloading: operator<<, operator+, ... #include using namespace std; class Cat { int wet; public: Cat( ) { wet=0; cout << "( " << wet<< " born. ";} Cat(int x){wet=x; cout << "( " << wet<< " appears. ";} Cat(const Cat& x){wet=x.wet; cout << "( " << wet<< " Copy. ";} Cat& operator=(const Cat&x) {wet=x.wet; cout << " [op] "; return *this;} Cat& operator+(const Cat&x) {wet += x.wet; cout << "=add= "; return *this;} friend ostream& operator<<(ostream&river, const Cat&); ~Cat( ) { cout << "[" << wet << "dying. "; } }; int main( ) { Cat x; Cat y(x); // copy constructor Cat m(38); // Cat(int) cout << "x=" << x << endl; cout << "y=" << y << ", m=" << m << endl; cout << "\n--------\n"; m = x+y; cout << "m=" << m << endl; cout << "\n-------- --------\n"; m = x+ 38; cout << "m=" << m << endl; } ostream& operator<<(ostream&river, const Cat&x) { river << x.wet; return river; } /****** C:\cpp>g++ cat.cpp C:\cpp>a ( 0 born. ( 0 Copy. ( 38 appears. x=0 y=0, m=38 -------- =add= [op] m=0 -------- -------- ( 38 appears. =add= [op] [38dying. m=38 [38dying. [0dying. [38dying. C:\cpp> ******/