c++ - When a derived class exits scope, does the base members get destroyed? -
I'm thinking one thing and no relevant answer can be found (maybe I'm just searching for the wrong things? ) For this:
If a derived class exits from the scope (called the destroyer), will the members of the base class be destroyed (even if the destroyers be removed?).
The idea is that destructors are used to remove any dynamic memory or to close a hook (file etc.). So if I have a managed member (for example string) will it still be destroyed?
Sorry if the question is stupid or has been answered before! Best regards, Eric
Yes, the builders of the base class are called when an example of a derived class Is destroyed. If you have a derived object through an indicator on the delete
basis:
class B {public: ~ B (); } Category D: Public B {Public: ~ D (); }; Zero F () {b * p = new d (); Remove p; // (maybe) will not call ~ D ()}
To create cases like work above, declared ~ b () to be virtual
should go.
class B {public: virtual ~ (b); };
Comments
Post a Comment