同样的代码:
test.h:
#ifndef TEST_H
#define TEST_H
#include <iostream>
using namespace std;
class Employee
{
public:
Employee();
virtual ~Employee();
};
class Singer : public Employee
{
public:
Singer();
~Singer();
};
#endif // TEST_H
test.cpp:
#include "test.h"
Employee::Employee()
{
cout << "Employee::Employee()" << endl;
}
Employee::~Employee()
{
cout << "Employee::~Employee()" << endl;
}
Singer::Singer()
{
cout << "Singer::Singer()" << endl;
}
Singer::~Singer()
{
cout << "Singer::~Singer()" << endl;
}
main.cpp:
#include <iostream>
#include "test.h"
using namespace std;
int main()
{
cout << "Hello world!" << endl;
Employee *pe = new Singer;
delete pe;
return 0;
}
上面的例子用来验证:当用父类指针指向子类对象,删除父类指针时,析构函数的执行顺序的;
codeblock直接把:~Singer()函数给吃了...
指不定后面又遇到什么坑,暂时不用了...