[xsd-users] use of auto_ptr

Boris Kolpackov boris at codesynthesis.com
Wed Apr 4 04:24:00 EDT 2007


Hi Guy,

Guy Kroizman <kroiz at hyperroll.com> writes:

> I noticed all the function that create my main object return auto_ptr.
> what if I want to construct an object that is not bound to the scope in
> which it is created?

The object is dynamically allocated exactly to allow it to survive
beyond the current scope if needed. The alternative to returning it
inside auto_ptr is to return a naked pointer but this is not
exception-safe.

As you said, you can always detach the underlying pointer from auto_ptr
(with the release() call) and store it anywhere you want (e.g., in
boost shared_ptr or as a member of a class). We use auto_ptr because
it is available as part of the standard C++ library and doesn't require
any external dependencies.


hth,
-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20070404/2f6831fe/attachment.pgp


More information about the xsd-users mailing list