In C++, a trivial destructor
is a recursively defined concept -- it's a destructor that the compiler wrote for you
when every member of the class (and every base class) has a trivial destructor. (There's
a similar concept called the trivial
constructor.)
When an object with a nontrivial
destructor is included in an object (like the vector in your
example), then the destructor of the outside object (like your
Derived) in is no longer trivial. Even though you didn't write
destructor, the C++ compiler automatically wrote a destructor that calls the destructors
of any members that have
destructors.
So, even though you
didn't write anything, the caveats of writing a non-virtual destructor still
apply.
No comments:
Post a Comment