STL container of auto_ptr

B

Boston

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?
 
A

Alf P. Steinbach

* 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.
 
B

Boston

Alf P. Steinbach said:
* Boston:

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



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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top