Just a conceptual question that I've been running into. In my current project it feels like I am over-using the boost smart_ptr
and ptr_container
libraries. I was creating boost::ptr_vectors
in many different objects and calling the transfer() method to move certain pointers from one boost::ptr_vector
to another.
It is my understanding that it is important to clearly show ownership of heap allocated objects.
My question is, would it be desirable to use these boost libraries to create heap-allocated members that belong to an object but then use normal pointers to these members via get()
when doing any processing.
For example...
A game might have a collection of Tiles that belong to it. It might make sense to create these tiles in a boost::ptr_vector
. When the game is over these tiles should be automatically freed.
However if I want to put these Tiles in a Bag object temporarily, should I create another boost::ptr_vector
in the bag and transfer the Game's Tiles to the Bag via transfer()
or
should I create a std::vector<Tile*>
where the Tiles*'s reference the Tiles
in the Game and pass that to the Bag?
Thanks.
**Edit I should point out that in my example The Game would have a Bag object as a member. The Bag would only be filled with Tiles the game owns. So the Bag would not exist without the Game.