Вопрос

I have a class that constructs an auto_ptr<T> and gets the T object data filled by a utility function. However, I want the T object stored by an object manager that will persist the whole life of the application.

The question is - once I have extracted the object that the auto_ptr contains, how do I stop the auto_ptr from destroying the contained object when it goes out of scope?

Это было полезно?

Решение

Apologies for my oversight. From the auto_ptr documentation;

http://www.cplusplus.com/reference/memory/auto_ptr/release/

std::auto_ptr::release

Release pointer

Sets the auto_ptr internal pointer to null pointer (which indicates it points to no object) without destructing the object currently pointed by the auto_ptr.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top