|
-
June 24th, 2010, 11:41 AM
#6
Re: Why does std::vector require its elements to be assignable?
 Originally Posted by HighCommander4
But suppose you don't do any of those things? Suppose all you do is add elements to the vector using push_back()? Aren't member functions of template classes only instantiated if they're actually used? So shouldn't a piece of code that only calls push_back() compile even if the element type is not assignable?
No - it is a template which means the the requirements are the same for all types used to instantiate the vector. If an object is created on the stack and then passed to push_back, then the object has to be deep copied. I don't see what the big deal is. Vector isn't special. All sequence containers require the types to be assignable unless you are inserting pointers.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|