2012-05-02 66 views
3

我们能否将std :: auto_ptr转换为普通指针?auto_ptr正常指针转换

​​

是否可以将本地创建的auto_ptr指针转换为普通指针。

+4

顺便说一句,'的std :: auto_ptr'现在已不支持'std :: unique_ptr'。 –

+0

非常感谢您的宝贵建议 –

回答

8

使用release()

Test* function() 
{ 
    std::auto_ptr<Test> test(new Test()); 

    return test.release() 
} 
3

是否可以将本地创建的auto_ptr指针转换为普通指针。

是:

return test.release();