As others have said, auto_ptr is the wrong thing, it is better to use std :: vector. But you can also use boost :: scoped_array. But note that you want to reset at the time of creation, otherwise you could use delete. pointer.reset (new int [2]);
or better yet, like this boost :: scoped_array arr (new int [2]);
It also makes no sense to create a static pointer std :: auto_ptr; on a global scale. This means that it will only be deleted when the program exists, which happens anyway, even if you skip memory.
source share