[LC++]STL and auto_ptr woes

Vincent Penquerc'h Vincent.Penquerch at artworks.co.uk
Thu Mar 7 03:01:05 UTC 2002


> I don't think that auto_ptr<> supports the assignment 
> operator--it only
> supports initialization via the constructor.  That's why it 
> won't work in
> your scenario.

[...]

> Is auto_ptr<> supposed to work in a Standard C++ Library 
> collection?  I seem
> to recall this as being a no-no, but I don't have the book in 
> front of me
> right now.

I think you answered your own question. I vaguely remembered
that auto_ptr is an STL collection would fail because of
ownership issues when being copied (auto_ptr, IIRC, transfers
ownership when assigned, so it does not actually duplicate
but gives (mv rather than cp), so the original collection
will now hold invalid data). That's what I think I remember,
I think I got the actual fully explained reason in one of
Scott Meyer's books, but it's quite fuzzy now, so I could be
utterly wrong.

-- 
Vincent Penquerc'h 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.linux.org.au/pipermail/tuxcpprogramming/attachments/20020307/f52c3d95/attachment.htm 


More information about the tuxCPProgramming mailing list