#include<iostream>
#include<string>
using namespace std;
class fa{
public:
void fast(){
cout << "父类中的成员函数调用" << endl;
}
fa(){
cout << "fa构造函数" << endl;
}
~fa(){
cout << "fa析构函数" << endl;
}
};
class son :public fa{//继承的实现
public:
void fast(){
cout << "子类中成员函数调用" << endl;
}
son(){
cout << "son构造函数" << endl;
}
~son(){
cout << "son析构函数" << endl;
}
};
void test(){
son p;
p.fast();//默认先调用子类中的成员函数
p.fa::fast();//加入作用域就能调用父类中的成员函数
}
int main(){
test();
}
用子类对象进行调用时,首先调用父类的构造函数,在调用子类的构造函数,在调用析构函数是与构造函数相反。