general questions
Now I've been reading quite a bit about smart pointers, and shared pointers seem like "perfect" in many cases. However I also read about cyclical reference or something like that? Where shared_ptr
can't be used? I'm having a difficult time undestanding this, can someone give a trivial example showing this?
Also I'm really wondering, what do weak_ptr's provide that normal pointers don't? - As they don't increase the reference count they give no guarantee that the memory they point at is still valid?
my personal project:
In a project I've 2 "global" containers (both containers are soon to be moved inside a class), both are filled with "objects". However both should "point" to the same object. An object can not exist outside those containers, and it should not be possible that one container does contain it, while the other doesn't.
Currently I simply use normal pointers for this, and have a createObject
& destroyObject
method to manage the memory.
Is this good design? Should I use smart pointers?