Talk:Auto ptr

How to free alloced and new[] objects ?
So what to do, if I have pointers to objects allocated with malloc or new[] (which are not handled by auto_ptr) ? --Xerces8 (talk) 08:38, 5 November 2008 (UTC)
 * For malloc, you use free. For new[], you use delete[]. Superm401 - Talk 11:44, 19 December 2008 (UTC)


 * Yes, and for new one uses delete. Now back to auto_ptr (that is automatic freeing of the object(s)) ;-) --Xerces8 (talk) 15:12, 19 December 2008 (UTC)
 * Not possible with auto_ptr. Consider using a vector instead of new[]. Third-party solutions also exist (boost::shared_array), if you can provide a scenario where vector can't be used :). decltype 09:54, 6 March 2009 (UTC)

Renaming this article to follow a consistent convention
Hi, I am currently considering renaming this article to conform to a common convention for C++ Standard Library components. The full discussion can be found here. decltype 09:48, 6 March 2009 (UTC)

A slightly different implementation in Nicolaï Josuttis book
In his book The C++ Standard Library, A Tutorial and Reference, 21st Printing, January 2008, p. 51, Nicolaï Josuttis - member of the Standard Committee library working group - gives a slightly different version, available on http://www.josuttis.com/libbook/ (index of all examples/auto_ptr implementation).

He describes it as follows (p. 51 note 6):

This is a slightly improved version that fixes some minor problems of the version in the C++ standard (auto_ptr_ref is global now and there is an assignment operator from auto_ptr_ref to auto_ptr; see page 55). Ptyxss (talk) 15:49, 23 June 2009 (UTC)

Use of auto_ptr to make object constant
I've removed the text below from the article, because I think it is a bad example. You can equally well use a const reference to an object to make the object constant. One could still try to use the open_vec, leading to a runtime error (which is not better than accidentally changing the vec), and it involves extra code (at runtime + in lines) to enforce compile-time constness-checks, which I think is not something which should be advised.

anoko_moonlight (talk) 12:51, 29 November 2015 (UTC)

Remove text:

However, an  containing an STL container may be used to prevent further modification of the container.