LearnFrenzy
Sign in Take a free test

Templates · Templates MCQ · Question 18

What is a forwarding reference? Answer, explanation & discussion

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

In template <typename T> void f(T&& x), what kind of reference is x?

  • A Always an rvalue reference
  • B A forwarding (universal) reference: it binds to lvalues and rvalues, and std::forward<T>(x) preserves which one it was Correct
  • C A const reference
  • D A pointer
Correct Answer: Option B

Reference collapsing makes T&& become an lvalue reference when an lvalue is passed.

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