C++中派生类能继承基类的构造函数和析构函数吗?
如题!能否举例体现一下?
可以的
#include <iostream>
using namespace std;
class Person
{
public:
Person()
{
cout << "Person's constructor is invoked" << endl;
}
~Person()
{
cout << "Person's destructor is invoked" << endl;
}
};
class Employee:public Person
{
public:
Employee()
{
cout << "Employee's constructor is invoked" << endl;
}
~Employee()
{
cout << "Employee's destructor is invoked" << endl;
}
};
int main()
{
Employee emloyee;
return 0;
}