/*虚函数(2)*/
class CEmployee
{
public:
CEmployee()
{
nTemp = 9;
}
virtual ~CEmployee();
public:
int nTemp;
virtual void ShowWage(void)
{
cout << this << ": 员工发工资方法" << endl;
}
};
class CItemManager : public CEmployee
{
public:
CItemManager();
//虚函数表中的第一个虚函数,写在第一个,所以表中也会是第一个(第0个)
virtual ~CItemManager();
public:
//虚函数表中的第二个虚函数 写在第二个,所以表中也会是第二个(第1个)
virtual void ShowWage(void)
{
cout << this << ": 项目经理发工资方法" << endl;
}
};
int main(int argc, char* argv[])
{
CEmployee *theEmployee1 = NULL;
theEmployee1 = new CItemManager;
//调用虚函数
theEmployee1->ShowWage();
if (theEmployee1)
{
//这里会调用析构函数,也是虚函数
delete theEmployee1;
theEmployee1 = NULL;
}
}