For both user-defined or implicitly-defined destructors, after the body of the destructor is executed, the compiler calls the destructors for all non-static non-variant members of the class, in reverse order of declaration, then it calls the destructors of all direct non-virtual base classes in reverse order of construction (which in turn call the destructors of their members and their base classes, etc), and then, if this object is of most-derived class, it calls the destructors of all virtual bases.
在Destructor調(diào)用完成后,成員的Destructor調(diào)用前,this的狀態(tài)是這樣的:

image.png
如果在析構(gòu)成員B時,使用了成員A,那么需要手動獲取A的指針,而不是使用this捕獲。因為這時的this已經(jīng)是失效的了:
std::shared_ptr<A> dump_a = this->a;
this->b = std::shared_ptr<B>(this->a->CreateB(),
[this, dump_a](B* p)
{
dump_a->ReleaseB(p); // OK
this->a->ReleaseB(p); // Error
});