#include <vector>
#include <iostream>
#include <string>
using namespace std;
class human
{
protected:
string _name;
public:
human()
{
};
~human()
{
cout << "parent" << endl;
};
string getName() {return _name;};
void setName(string aName) {_name = aName;};
};
class man : public human
{
public:
man() : human() {};
~man()
{
cout << "child" << endl;
};
};
int main()
{
human human1;
man man1;
return 1;
#include <iostream>
#include <string>
using namespace std;
class human
{
protected:
string _name;
public:
human()
{
};
~human()
{
cout << "parent" << endl;
};
string getName() {return _name;};
void setName(string aName) {_name = aName;};
};
class man : public human
{
public:
man() : human() {};
~man()
{
cout << "child" << endl;
};
};
int main()
{
human human1;
man man1;
return 1;
}
输出结果:
child
parent
parent
程序结束前自己析构,且派生类类会调用基类的
析构函数。