码迷,mamicode.com
首页 > 编程语言 > 详细

C++11 Universal Reference

时间:2018-06-08 16:38:16      阅读:380      评论:0      收藏:0      [点我收藏+]

标签:ted   com   ecif   turn   case   universal   ++   otherwise   imp   

 

Q1. 什么是universal reference?

If a variable or parameter is declared to have type T&& for some deduced type T, that variable or parameter is a universal reference.

 

Q2. 什么是deduced typeT?

A2. Template parameter、auto declaration, ect.

 

Q3. universal reference 是什么类型?

  • If the expression initializing a universal reference is an lvalue, the universal reference becomes an lvalue reference.
  • If the expression initializing the universal reference is an rvalue, the universal reference becomes an rvalue reference.

Q4. 什么是lvalue(左值),什么是rvalue(右值)? 

The C++11 standard generally specifies whether an expression is an lvalue or an rvalue on a case-by-case basis

  通常可以这么归纳:

  • If you can take the address of an expression, the expression is an lvalue.
  • If the type of an expression is an lvalue reference (e.g., T& or const T&, etc.), that expression is an lvalue. 
  • Otherwise, the expression is an rvalue.  Conceptually (and typically also in fact), rvalues correspond to temporary objects, such as those returned from functions or created through implicit type conversions. Most literal values are also rvalues.

 

C++11 Universal Reference

标签:ted   com   ecif   turn   case   universal   ++   otherwise   imp   

原文地址:https://www.cnblogs.com/wangpei0522/p/9156275.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!