I can't find a complete example that shows how to eliminating strong circular references between shared_ptr
.
Problem is how to use a weak_ptr
to "close" the chain of generic elements and to access the "next" element with the weak_ptr
.
Thank you.
EDIT:
For example, suppose to have Element e1, e2, e3;
with pointer inside to the next element.
In C we do
e1->Next = e2;
e2->Next = e3;
e3->Next = e1;
...and we could do e1->Next->Next->Next->Next->Next
etc.
In C++ with shared_ptr
we cannot do the last ->Next = e1
because of circular references and destructor will not release all the Element
.
We need a weak_ptr
: but what strategy to have the same result?