引用的类型必须和引用的对象类型一致,但是两个例外,第一,初始化常量引用的时候允许用任意表达式作为初始值 例如double dval =3.14; const int & ri = dval; 就相当于const int tmp = dval; const int &ri =dval; 编译器创建了一个临时对象。注意此时的绑定对象是tmp而非dval
int i=42; const int & r2 = i; 这样的情况下,不允许通过r2修改i的值
指向常量的指针(pointer to const)const int * pi =&pii; 和常量指针(const pointer) int * const pi =&pii; 同理从 右边向左边阅读
int i =42, *p = &i, &r =i;
decltype(r+0) b;//b是整形(int),因为运算结果是int
decltype (*p) c;//这里的c是引用(&int),因为decltype解引用就是得到引用
Remember that decltype(( variable )) (note, double parentheses) is always
a reference type, but decltype( variable ) is a reference type only if variable
is a reference.
Headers (usually) contain entities (such as class definitions and const and
constexpr variables (§ 2.4, p. 60)) that can be defined only once in any given file.