KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
When invoking the method push_back from std::vector , its size is incremented by one, implying in the creation of a new instance, and then the parameter you pass will be copied into this recently created element, right? Example: myVector.push_back(MyVectorElement()); Well then, if I want to increase the size of the vector with an element simply using its default values, wouldn't it be better to use the resize method instead? I mean like this: myVector.resize(myVector.size() + 1); As far as I can see, this would accomplish exactly the same thing but would avoid the totally unnecessary assignment copy of the attributes of the element. Is this reasoning correct or am I missing something?
Tags (comma-separated)
Save Edits
Cancel