LearnFrenzy
Sign in Take a free test

Constructors and Destructors · Constructors MCQ · Question 19

What is guaranteed copy elision? Answer, explanation & discussion

  • MCQ
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 19 Back to Exercise

In C++17, what happens with T make() { return T(42); } and T t = make();?

  • A Two copies are made
  • B T is constructed directly in t – no copy or move constructor is called Correct
  • C One move is always made
  • D It depends on optimization level
Correct Answer: Option B

Returning a prvalue is guaranteed to construct in place. Returning a named local (NRVO) is only permitted, not guaranteed.

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links