DDDerived class dtor, which should not explicitly invoke C or B.
CCComponent (ie field) dtor
BBBase dtor
CCComponent of BBBase class
Compiler arranges these steps to execute in a single thread. See P277 ARM
A1: same DCBC according to EffC++. I probably tested it.
A3: See P60 [[safe c++]]. The exception triggers stack unwinding -- C B C. Exact same sequence except the very first step i.e. the D is skipped. Derived dtor is skipped because Derived ctor didn't complete. The simple rule in this "exceptional" scenario is "whenever a ctor completes without throwing, its dtor would be executed."
Quizzes:
Q1: but what if i invoke Derived virtual dtor through "delete"?
Q2: Virtual base?
Q3: what if the derived ctor throws exception after B and C completed? Which dtors will/won't run and in what order?
(To aid blog search, D-C-B-C)
No comments:
Post a Comment