Question
What does the C ++ standard mean about the state of an object at a time after executing the destructor of the derived class, but before executing the destructor of the base class? (This is the time when sub-object destructors of the derived class are called).
Example
#include <string>
struct Base;
struct Member {
Member(Base *b);
~Member();
Base *b_;
};
struct Base {
virtual void f() {}
virtual ~Base() {}
};
struct Derived : Base {
Derived() : m(this) {}
virtual ~Derived() {}
virtual void f() {}
std::string s;
Member m;
};
Member::Member(Base *b) : b_(b) {}
Member::~Member() {
b_->f();
}
int main() {
Base *bd = new Derived;
delete bd;
}
In this example, the object Memberhas a pointer to the object Derivedto which it belongs, and it tries to access this object Derivedas it is destroyed ... although the destructor for is Derivedalready completed.
What version of virtual functions *bdis called if any subobject called virtual function is ~Derived()executed after but before execution ~Base()? Is access legal *bdwhen it is in this state?