struct A
{
virtual ~A() { this->f(); }
virtual void f() {};
};
struct B : A
{
int* p;
B() : p(new int) {}
~B()
{
delete p;
p = 0;
}
void f() override { *p = 0; }
};
int main()
{
delete new B; // Is it safe?
}
在虚拟析构函数中调用其他虚拟方法是否安全?在虚拟析构函数中调用其他虚拟方法是否安全?
如果为纯虚拟提供了一个主体,那么它并不是未定义的。 –
我问了一个问题,以确保.. http://stackoverflow.com/questions/18456450/is-it-safe-to-call-a-pure-virtual-function-in-an-abstract-constructor-destructor –