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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:29:41+00:00 2026-06-12T16:29:41+00:00

What is the lifetime of a C++ class member. For example, at which time

  • 0

What is the lifetime of a C++ class member. For example, at which time will the std::fstream of a Foo object be released? When entering the destructor or when leaving the destructor? Is this defined in the C++ standard?

struct Foo
{
    std::fstream mystream;
    ~Foo()
    {
        // wait for thread writing to mystream
    }
};
  • 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-12T16:29:42+00:00Added an answer on June 12, 2026 at 4:29 pm

    The mystream data member is destroyed during the destruction of the Foo object, after the body of ~Foo() is executed. C++11 §12.4[class.dtor]/8 states:

    After executing the body of the destructor and destroying any automatic objects allocated within the body, a destructor for class X calls the destructors for X‘s direct non-variant non-static data members, the destructors for X‘s direct base classes and, if X is the type of the most derived class, its destructor calls the destructors for X‘s virtual base classes.

    mystream is a non-variant, non-static data member of Foo (a variant data member is a member of a union; Foo is not a union).

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

Sidebar

Related Questions

Code example: unit Foo; TFoo = class protected FList: TList; // Lifetime is managed
I have a class called Foo which has a member that is a pointer
I basically have a vector<Object> vec_; as a class member in a cpp class.
I have a framework function which expects an object and a member function pointer
Suppose I have a class module clsMyClass with an object as a member variable.
I have a class hierarchy, each member of which may create IDisposable objects. I
In C++, the lifetime of an object begins when the constructor finishes successfully. Inside
I am new to programming and am having difficulty with understanding object lifetime /
I've got class which is using plain-only-data struct with const variables and I'm not
My question (which will follow after this, sorry about the long intro, the question

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.