为什么父类的析构函数定义成virtual后,deletepTest2就会释放Derived的资源,否则就只能释放Base的资源,而deletepTest1就能释放Derived和Base的资源classBase{public:~Base(){cout<<"Basedestructor!"<}; };classDerived:publicBase{public:~Derived(){cout<<"Deriveddestructor!"<}; };intmain(){Derived*pTest1=newDerived();Base*pTest2=newDerived();deletepTest1;deletepTest2;return0;}
GCT1015
相关分类