构造函数: 父类的先执行,子类的后执行
析构函数: 父类的后执行,子类的先执行
T1.h //父类
#ifndef k //防止头文件重复包含的问题
#define k
#include<iostream>
using namespace std;
class T1
{
public:
T1()
{
cout<<"T1's constructor is run !"<<endl;
}
virtual ~T1()
{
cout<<"T1's destructor is run !"<<endl;
}
};
#endif
T2.h
#ifndef k2
#define k2
#include<iostream>
#include"T1.h"
using namespace std;
class T2 : public T1
{
public:
T2()
{
cout<<"T2's constructor is run !"<<endl;
}
virtual ~T2()
{
cout<<"T2's destructor is run !"<<endl;
}
};
#endif
main.cpp
#include "T1.h"
#include "T2.h"
void main()
{
// T1