468,765 Members | 1,368 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,765 developers. It's quick & easy.

STL container of auto_ptr

my version of the STL has the following documentation:

You can pass an auto_ptr<Type> object by value as an argument to a function
call. You can return such an object by value as well. Both operations depend
on the implicit construction of intermediate objects of class
auto_ptr<Type>::auto_ptr_ref<Other>, by various subtle conversion rules. You
cannot, however, reliably manage a sequence of auto_ptr<Type> objects with a
Standard Template Library container.

Is this restriction against having, say, a vector of auto_ptr normal? If
so, why?
Jul 23 '05 #1
2 1415
* Boston:

Is this restriction against having, say, a vector of auto_ptr normal?
It's in the standard, if that's what you're asking.

If so, why?


Technically because a std:.atuo_ptr is not a copyable object. Standard
containers require copyable objects. They copy things around.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jul 23 '05 #2

"Alf P. Steinbach" <al***@start.no> wrote in message
news:41****************@news.individual.net...
* Boston:

Is this restriction against having, say, a vector of auto_ptr normal?


It's in the standard, if that's what you're asking.

If so, why?


Technically because a std:.atuo_ptr is not a copyable object. Standard
containers require copyable objects. They copy things around.


Ah, because if you copy the auto_ptr, the source sets its ptr to NULL,
therefore it couldn't be const&. I understand now, thanks.
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by gg | last post: by
10 posts views Thread by dragoncoder | last post: by
9 posts views Thread by dragoncoder | last post: by
39 posts views Thread by Andre Siqueira | last post: by
18 posts views Thread by tech | last post: by
7 posts views Thread by tradevol | last post: by
17 posts views Thread by Ankur Arora | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.