Hi,
I suggest the following code:
class Master { typedef boost::smart_ptr<Slave> slave_ptr_t; typedef boost::smart_ptr<const Slave> slave_cst_ptr_t;
typedef std::vector
vec_slaves_t; typedef std::vector vec_cst_slaves_t;//defining
*Cyril Godart wrote:* this
one is good practice as you'll see later
Master(); Master(size_t i) { slaves_.resize(i);// assume slave has an empty ctor defined. }
vec_cst_slaves_t slaves() //something like const vec_cst_slaves_t& slaves() const should work { return slaves_; //nice casting that I failed to notice until someone in this list mentioned it to me };
vec_slaves_t slaves_; };
As you rightly guessed, a big advantage of this approach is that the plumbing of copy-assigment dtor and so on reduces drastically. I find it extremely convenient, even though there is a performance hit.
It would be a good choice to use vectors instead of arrays but since my project is a game i'm interested in performance penalties.(smart pointers will be used for memory management) I guess i can benchmark both ways and make my choice but i can't do that before making the arrays work the way i want.