25 Feb
2004
25 Feb
'04
9:19 p.m.
voodoo4@otenet.gr wrote:
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; }
class Master { // ... shared_array<Slave> sl; }; Master::Master(int val) : sl(new Slave[val]) { } Master::~Master() { // intentionally left blank! } Of course, you may want to use scoped_array<Slave> instead of shared_array<Slave>, but that depends on what you want to do. -- Colin