Using auto_ptr<> with array

balu picture balu · Jun 29, 2011 · Viewed 7.3k times · Source

I'm using auto_ptr<> which uses an array of class pointer type so how do I assign a value to it.

e.g. auto_ptr<class*> arr[10];

How can I assign a value to the arr array?

Answer

Armen Tsirunyan picture Armen Tsirunyan · Jun 29, 2011

You cannot use auto_ptr with array, because it calls delete p, not delete [] p.

You want boost::scoped_array or some other boost::smart_array :)