Question 13
Back to Exercise
What is the difference between v.emplace_back(1, "pen") and v.push_back(Order(1, "pen"))?
- A No difference
- B emplace_back constructs the element in place from the arguments; push_back takes an existing object (moving or copying it) Correct
- C push_back is always faster
- D emplace_back sorts the vector
Correct Answer: Option B
With move semantics the difference is often small, but emplace avoids the temporary.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!