kind of a silly question but I have a metaphysical doubt which is why I need to ask.
When pushing back an object to a vector, assuming I do not need to update the object beforehand, can I avoid the usage of a local variable ?
void addToVector(std::vector<Foo>& fooVector)
{
// Solution #1
Foo foo;
fooVector.push_back(foo);
// Solution #2
fooVector.push_back(Foo());
}
Would solution #2 leak memory knowing that there is no local variable going out-of-scope encapsulating Foo ?
Assuming solution #2 is valid, is it more efficient than solution #1 ? (emplace_back
would probably be, but I'm still stuck with c++03)