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 8638541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:45:24+00:00 2026-06-12T10:45:24+00:00

Possible Duplicate: Does C++ call destructors for global and class static variables? What is

  • 0

Possible Duplicate:
Does C++ call destructors for global and class static variables?

What is the lifetime of

  • global MyClass myclass;
  • global static MyClass myclass;
  • global const MyClass myclass;
  • global static const MyClass myclass;
  • function local static MyClass myclass; when its initialization actually occured
  • global static constexpr MyClass myclass; in C++11

and especially will they be destroyed on regular program end (i.e. main is left without an error)? Where does the standard states so.

I noticed that a private destructor prevents the creation of all those variables. But if I remember correctly it was explicitly mentioned somewhere that some static data may be put into a static data section and loaded pre-constructed, already. This would imply for me that no destructor would be called. And this would imply I am allowed to define such a variable…

  • 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. Editorial Team
    Editorial Team
    2026-06-12T10:45:25+00:00Added an answer on June 12, 2026 at 10:45 am

    The destructors of file or namespace scope objects get called when the control flow leaves main().

    If an exception leaves main() then it’s implementation defined whether the destructors of any objects get called. With modern compilers the destructors won’t be called in this case to allow easy inspection of the program state when the unhandled exception was thrown. Early C++ implementations used exception mechanism based on setjmp/longjmp which would unwind the stack while searching for the exception handler and hence calling destructors even if no suitable exception handler was eventually found.

    If an application terminates with _exit() or _Exit() or std::quick_exit() no destructors get called.

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

Sidebar

Related Questions

Possible Duplicate: What is The Rule of Three? How exactly does std::pair call destructors
Possible Duplicate: C++ Static member method call on class instance Today I discovered that
Possible Duplicate: Why does PHP 5.2+ disallow abstract static class methods? Why can't you
Possible Duplicate: Why does the Execution Plan include a user-defined function call for a
Possible Duplicate: In JavaScript, does it make a difference if I call a function
Possible Duplicate: C++ Vector Pointers to Objects Does std::list::remove method call destructor of each
Possible Duplicate: Does std::list::remove method call destructor of each removed element? I have a
Possible Duplicate: Does every thread need its own autorelease pool? I would like to
Possible Duplicate: Can you call Directory.GetFiles() with multiple filters? Does it possible to get
Possible Duplicate: Does std::list::remove method call destructor of each removed element? I have a

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.