Home > Back-end >  From and weak_ptr question
From and weak_ptr question

Time:12-27

I use this period of program
 # include & lt; Memory> 
#include
#include
using namespace std;

Void fun2 ();

The class Test
{
Public:
To Test ()
{
Fun2 ();
}
};
STD: : list LST.

Void fun2 ()
{
Auto iter=LST. The begin ();
While (iter!=LST. End ())
{
If (iter - & gt; Expired ())
Iter=LST. Erase (iter);
The else
+ + iter.
}
}

Void fun ()
{
From & lt; Test> S (make_shared & lt; Test> ());
LST. Push_back (s);
}

Int main ()
{
fun();
}


The program in the smart Pointers to destroy all testing weak_ptr content is deleted, if the content is deleted in the list delete weak_ptr
Now I want to ask next, do that expired in the destructor is legal, have defined the behavior (execution from the management of the object's destructor, weak_ptr expired for true)
  • Related