Auto_ptr for normal pointer conversion

Is it possible to convert std :: auto_ptr to a regular 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 the auto_ptr pointer, which is created locally for a regular pointer.

+3
source share
3 answers

Use release ()

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

  return test.release()
}
+8
source

Is it possible to convert the auto_ptr pointer, which is created locally for a regular pointer.

Yes:

return test.release();
+3
source

See the release method for std :: auto_ptr: http://www.cplusplus.com/reference/std/memory/auto_ptr/release/

+1
source

All Articles