Monday, 26 August 2013

Is it safe to call a pure virtual function in an abstract constructor/destructor, IF it has a body?

Is it safe to call a pure virtual function in an abstract
constructor/destructor, IF it has a body?

Without the line marked BODY, I know this is not safe. But with it, is
this safe? (Concerns about virtual lookup behaving differently in
constructors/destructors aside).
struct A
{
virtual ~A() { f(); }
virtual void f() = 0;
};
void A::f() {} // BODY
struct B : A
{
void f() {}
};
int main()
{
delete new B;
}
Working example: http://ideone.com/9bRZ3i

No comments:

Post a Comment