LearnFrenzy
Sign in Take a free test

References: lvalue and rvalue · References MCQ · Question 16

Why use std::forward? Answer, explanation & discussion

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

Why is std::forward<T>(arg) used inside a function taking T&& arg?

  • A To make a copy
  • B To pass arg on with its original value category – rvalues as rvalues, lvalues as lvalues Correct
  • C To convert arg to a pointer
  • D To check arg for null
Correct Answer: Option B

Without it the named parameter is always an lvalue, so temporaries would be copied instead of moved.

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