Hello people.
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);
AFAICS (As Far As I Can See), this would accomplish exactly the same but would avoid the totally unnecessary assignment copy of the attributes of the element.
Is this reasoning correct or am I missing something?
Thanks!