|
Boost Users : |
From: Colin Rafferty (colin.rafferty_at_[hidden])
Date: 2004-02-25 16:19:06
voodoo4_at_[hidden] 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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net