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
I downloaded yesterday the boost libraries (mainly for the memory libs) and to tell the truth i'm impressed with pool and smart pointers. Especially the boost smart pointers will save me from months of coding! However i have a question about smart pointers.
Let's say i have these objects(the code is just an example):
class Slave { Slave(); ~Slave(); };
class Master { Master(); Master(int size); ~Master();
Slave *sl; };
I want "sl" to be an array of Slaves on the free store but the sized will be determined in the constructor.
With normal pointers i would write:
Master::Master(int val) { sl=new Slave[val]; }
Master::~Master() { delete sl; }
How can i achieve the same with boost smart pointers?
I have no idea (see below).
I've read the manual three or four times but i still don't get how to work this out. Does this have something to do with the empty ptr? I believe solution is in front of my eyes but i'm too blind(as usual) to see it...
I don't think you're using the right tool for the job. From what I know, smart pointers should be used when you have one object, here you (potentially) have many. I think what you really want to do here is to use a container class like stl::list or stl::vector to contain your slave objects. If you still want to use smart pointers, I guess you could use a list of smart pointers, but there's really no point for that if your slave class is properly coded (for instance, has a ctor, copy ctor, virtual dtor, and operator=). --MP _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users This message and any attachments (the "message") is intended solely for the addressees and is confidential. If you receive this message in error, please delete it and immediately notify the sender. Any use not in accord with its purpose, any dissemination or disclosure, either whole or partial, is prohibited except formal approval. The internet can not guarantee the integrity of this message. BNP PARIBAS (and its subsidiaries) shall (will) not therefore be liable for the message if modified. --------------------------------------------- Ce message et toutes les pieces jointes (ci-apres le "message") sont etablis a l'intention exclusive de ses destinataires et sont confidentiels. Si vous recevez ce message par erreur, merci de le detruire et d'en avertir immediatement l'expediteur. Toute utilisation de ce message non conforme a sa destination, toute diffusion ou toute publication, totale ou partielle, est interdite, sauf autorisation expresse. L'internet ne permettant pas d'assurer l'integrite de ce message, BNP PARIBAS (et ses filiales) decline(nt) toute responsabilite au titre de ce message, dans l'hypothese ou il aurait ete modifie.