//基類: #include <iostream.h> class Animal() { public: Animal(int height,int weight) { cout<<"Animal"<<endl; } void eat() { cout<<"animal eat"<<endl; } }; //子類: class fish:public Animal() { public: fish():Animal(400,300),a(20)//在子類fish中向父類的構造函數傳遞參數.a(20)是初始化fish類中的常量a { cout<<"fish"<<endl; } private: const int a; }; //說明:在子類中調用父類的帶參數的構造函數,在fish類的構造函數後,加一個冒號(:),然後加上父類的帶參數的構造函數.這樣,在子類的構造函數被調用哪個時,系統就會去調用父類的帶參數的構造函數去構造對象.