//abc.cpp #include using namespace std; class Dog { public: Dog() { wet=38; cout << "Wan wan! "; } // constructor protected: int wet; // so that can be used in GueiDog friend int main( ); }; // do NOT forget the ";" class GueiDog : public Dog { public: GueiDog( ) { wet=49; cout << "貴賓狗! "; } // constructor }; // do NOT forget the ";" int main( ) { Dog x; Dog * x2; // note that x2 is a pointer cout << "x.wet = " << x.wet; cout << endl << "Ha ha ha 來個 GueiDog:\n"; GueiDog y; cout << "y.wet = " << y.wet << endl; cout << "------\n"; x2 = new Dog( ); // 這時才生出 Dog }//main( /****** D:\COURSE\OOP> g++ abc.cpp D:\COURSE\OOP> a.exe Wan wan! x.wet = 38 Ha ha ha 來個 GueiDog: Wan wan! 貴賓狗! y.wet = 49 ------ Wan wan! D:\COURSE\CS001\talk> *******************************************/