auto_ptr to normal pointer conversion
سؤال
Are we able to convert a std::auto_ptr to a normal pointer??
class Test
{
......
}
Test* function()
{
std::auto_ptr<Test> test(new Test());
return _____//TODO : need to convert this auto_ptr to Test*
}
Is it possible to convert an auto_ptr pointer which is created locally to normal pointer.
المحلول
Use release()
Test* function()
{
std::auto_ptr<Test> test(new Test());
return test.release()
}
نصائح أخرى
Is it possible to convert an auto_ptr pointer which is created locally to normal pointer.
Yes:
return test.release();
See release method of std::auto_ptr: http://www.cplusplus.com/reference/std/memory/auto_ptr/release/
لا تنتمي إلى StackOverflow