Boost logo

Boost Users :

Subject: Re: [Boost-users] how to create smart pointer array?
From: Igor R (boost.lists_at_[hidden])
Date: 2013-01-30 13:49:48


> 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]);
> }

Problem 1 (minor): scoped_ptr is not assignable.
Problem 2 (critical): on destruction, scoped_ptr will call operator
delete, instead of operator delete[].

Use shared_array instead.


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