//dog22.cpp -- LionDog extends Dog #include using namespace std; class Dog { protected: int wet; public: int getWet( ) { return wet;} void setWet(int k) { wet=k; } Dog( ) { wet=11; cout << "Dog-" << wet << " born.\n"; } Dog(int x) { wet=x; cout << "Dog-" << wet << " appears.\n"; } friend int ar3(Dog); ~Dog( ) { cout << " [dog--" << wet << " is dying.\n"; } }; class LionDog: public Dog { public: LionDog( ) { cout << "Lion.."; } LionDog(int k): Dog(k*10) { cout << ":lion:+"; } ~LionDog( ) { cout << "LionDog--"<< wet << " going to dye.\n";} }; Dog x; Dog *p; int ar3(Dog x){ return x.wet; } // OK, friend int main( ) { Dog y(250); cout << "Welcome ..."; cout << "x = " << x.getWet( ) << endl; x.setWet(38); cout << " ar3 said x = " << ar3(x) << endl; p = new Dog(49); cout << " dog p = " << p->getWet( ) << endl; delete p; cout << "bye bye===\n"; } /***** 12:35pm ccbsd2:dogLionDog/> g++ dog22.cpp 12:35pm ccbsd2:dogLionDog/> ./a.out Dog-11 born. Dog-250 appears. Welcome ...x = 11 ar3 said x = 38 [dog--38 is dying. Dog-49 appears. dog p = 49 [dog--49 is dying. bye bye=== [dog--250 is dying. [dog--38 is dying. 12:35pm ccbsd2:dogLionDog/> *****/