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
}
};
The
mystreamdata member is destroyed during the destruction of theFooobject, after the body of~Foo()is executed. C++11 §12.4[class.dtor]/8 states:mystreamis a non-variant, non-static data member ofFoo(a variant data member is a member of a union;Foois not a union).