how to create smart pointer array?
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]); } ... -- View this message in context: http://boost.2283326.n4.nabble.com/how-to-create-smart-pointer-array-tp46420... Sent from the Boost - Users mailing list archive at Nabble.com.
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.
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
participants (3)
-
Igor R
-
Nathan Crookston
-
young