Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 152607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:39:13+00:00 2026-05-11T09:39:13+00:00

What is the order in which the destructors and the constructors are called in

  • 0

What is the order in which the destructors and the constructors are called in C++? Using the examples of some Base classes and Derived Classes

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T09:39:14+00:00Added an answer on May 11, 2026 at 9:39 am

    The order is:

    1. Base constructor
    2. Derived constructor
    3. Derived destructor
    4. Base destructor

    Example:

    class B { public:   B()   {       cout<<'Construct B'<<endl;   }    virtual ~B()   {     cout<<'Destruct B'<<endl;   } };  class D : public B { public:   D()   {       cout<<'Construct D'<<endl;   }    virtual ~D()   {     cout<<'Destruct D'<<endl;   } };    int main(int argc, char **argv) {   D d;    return 0; } 

    Output of example:

    Construct B

    Construct D

    Destruct D

    Destruct B

    Multiple levels of inheritance works like a stack:

    If you consider pushing an item onto the stack as construction, and taking it off as destruction, then you can look at multiple levels of inheritance like a stack.

    This works for any number of levels.

    Example D2 derives from D derives from B.

    Push B on the stack, push D on the stack, push D2 on the stack. So the construction order is B, D, D2. Then to find out destruction order start popping. D2, D, B

    More complicated examples:

    For more complicated examples, please see the link provided by @JaredPar

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called order which contains columns id , user_id , price
I'm executing an external application using the CreateProcess function, in order which such application
In the following code, what is the order in which the destructors of b
I have a class called Order which has properties such as OrderId , OrderDate
I have a table called service order which has columns called From and To.
I have a table called order which has many order_items , each order_items is
I have a table called order which has many order_items , each order_items is
In what order get the constructors of global object in C++ called? This question
I have a helper called user_order which returns an instance of Order . Order
I have 2 classes Base and Derived (derived publically from Base). When I write

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.