题目描述:C++中子类父类构造函数和析构函数的执行
代码如下:
1)当父类析构函数为虚函数时:
<span style="font-size:14px;">#include<iostream>
using namespace std;
class Father{
public:
Father(){
cout << "This is the father Structor !" << endl;
}
//父类析构函数为虚函数
virtual ~Father(){
cout << "This is the father Destructor !" << endl;
}
virtual void Find(){
cout << "This is the father Find !" << endl;
}
};
class Son :public Father{
public:
Son(){
cout << "This is the son Structor !" << endl;
}
~Son(){
cout << "This is the son Desturctor!" << endl;
}
void Find(){
cout << "This is the son Find !" << endl;
}
};
int main(){
cout << "-----------Father* a = new Father()------------" << endl;
F