struct IRing
{
virtual ~IRing(){};
virtual void printTable() = 0;
virtual int add(int a,int b) = 0;
virtual int mul(int a,int b) = 0;
virtual int size() = 0;
};
M2r::~M2r(){
#if 1
int ID=IdRing(this);
printf("R%d_%d: %s\n",size(),ID,__FUNCTION__);
#endif
if(m_flag==1 && m_r!=NULL){
delete m_r;
m_r=NULL;
}
}
int main()
{
M2r* r4_7=new M2r();
r4_7->initG(2);
IRing* r=r4_7;
delete r;// 如果抽象基类没有加上虚析构声明,那么M2r对象没有析构,
//delete r4_7;//M2r对象析构了
return 0;
}
D:\MathTool\gaptool>IRing
R4_7: M2r::~M2r
C++抽象基类的虚析构声明
最新推荐文章于 2023-06-17 21:14:07 发布