First, a non-pointer object is added, and the second adds a pointer to the vector. Thus, it all depends on the declaration of the vector as to what you should do.
In your case, since you declared objects as std::vector<DrawObject> , so the first one will work, since objects can store elements of type DrawObject , not DrawObject* .
In C ++ 11, you can use emplace_back as:
objects.emplace_back(name, surfaceFile, xPos, yPos, willMoveVar, animationNumber);
Pay attention to the difference. Compare this to:
objects.push_back(DrawObject(name, surfaceFile, xPos, yPos, willMoveVar, animationNumber));
With emplace_back you do not create an object on the call site, instead you pass arguments to the vector, and the vector internally constructs the object in place. In some cases, it can be faster.
Read the emplace_back doc that says (underline mine)
Adds a new item to the end of the container. The element is built in place, i.e. Copy or move operations are not performed . The element constructor is called with exactly the same arguments that the function provides.
Since it avoids copying or moving, the resulting code may be slightly faster.