Hi all,
I have a question regarding shared_ptrs and ownership in C++:
I have a bunch of objects created on the heap. Each one has a container which holds pointers to some of these objects, and sometimes, even a pointer to the same object the container belongs to. Since I read about the risks of using shared_ptr under such circumstances (circularity), I'm thinking about how to do it best. Luckily, there is a class that holds all of the objects in question (but not itself), so I thought I give it ownership over them, so that its container holds shared_ptrs while the objects in question hold raw pointers. That is, destruction of the class frees the heap-allocated memory. Is this (also in terms of design) a good decision to make?
Another thougth was not to let the objects hold pointers, but rather unique IDs. This would imply a lookup to actually get an object via its ID, however, I think it would also reduce critical dependecies among the objects. Is this preferable?
Regards,
Jena