$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] how to create smart pointer array?
From: Nathan Crookston (nathan.crookston_at_[hidden])
Date: 2013-01-30 13:59:23
young wrote:
> What is wrong with:
>
> boost::scoped_ptr<byte> buff[10];
> for(int i=0; i<10; i++)
> {
> int size = 2*i + 100;
> buff[i] = boost::scoped_ptr<byte>(new byte[size]);
> }
> ...
>
I agree with what Igor wrote. You could also use scoped array and change
your code thus:
#include <boost/scoped_array.hpp>
typedef unsigned char byte;
int main()
{
boost::scoped_array<byte> buff[10];
for(int i=0; i<10; i++)
{
int size = 2*i + 100;
buff[i].reset(new byte[size]);
}
}
HTH,
Nate
P.S. std::unique_ptr<byte[]> could also fit your needs, if that's available
with your compiler.