Vaibhav Kulkarni
Vaibhav Kulkarni

Reputation: 29

Constructor / Destructor calling sequence in inheritance

Why order of constructors called in inheritance is reverse than calls to destructors ? Any specific reason ?

Upvotes: 0

Views: 89

Answers (1)

catnip
catnip

Reputation: 25388

Yes there is. The order for constructors is base, derived. This ensures that the constructor for derived can rely on base being properly initialised while the derived constructor runs.

The order for destructors is derived, base. This ensures that derived can rely on base still being valid while the derived destructor runs.

Upvotes: 4

Related Questions