C++教程:C++虚函数与虚析构函数

2020-01-06 12:29:46于海丽

}
Cat::~Cat()
{
   cout <<"Cat destructor is running..." <<endl;
}
//main.cpp
#include "cat.h"
int main()
{
   Animal *pa=new Cat(2,1);
   Cat *pc=new Cat(2,4);
   cout <<"Delete pa:" <<endl;
   delete pa;
   cout <<"Delete pc:" <<endl;
   delete pc;
   return 0;
}

运行结果:
Animal consturctor is running...