1 #include <iostream> 2 #include <string> 3 4 using namespace std; 5 6 class FatherClass 7 { 8 public: 9 FatherClass(); 10 ~FatherClass(); 11 }; 12 13 FatherClass::FatherClass() 14 { 15 cout << "this is FatherClass constructor"<<endl; 16 } 17 18 FatherClass::~FatherClass() 19 { 20 cout << "this is FatherClass finalizer"<<endl; 21 } 22 23 class ChildClass:public FatherClass 24 { 25 public: 26 ChildClass(); 27 ~ChildClass(); 28 }; 29 30 ChildClass::ChildClass() 31 { 32 cout << "this is ChlidClass constructor"<<endl; 33 } 34 35 ChildClass::~ChildClass() 36 { 37 cout << "this is ChildClass finalizer"<<endl; 38 } 39 40 int main() 41 { 42 ChildClass a; 43 cout << "finished"<<endl; 44 return 0; 45 }
执行结果:
时间: 2024-10-15 10:00:52