No, you can't, and it won't: C ++ 98 is very limited when it comes to arrays, and auto_ptr
is a very uncomfortable beast that often doesn't do what you need.
You can:
use std::vector<int>
/ std::deque<int>
, or std::array<int, 10>
, or
use C ++ 11 and std::unique_ptr<int[]> p(new int[15])
, or
use C ++ 11 and std::vector<std::unique_ptr<int>>
(although this is too complicated for int
).
If the size of the array is known at compile time, use one of the static containers ( array
or a unique pointer to an array). If you need to resize at runtime, mostly use vector
, but for larger classes, you can also use a vector of unique pointers.
std::unique_ptr
is what std::auto_ptr
wanted, but could not because of language restrictions.
source share