C++11 中的自动引用 [英] auto reference in c++11

查看:40
本文介绍了C++11 中的自动引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在关于自动引用时遇到了一些问题.

I have some trouble about auto reference.

const int i = 1;
auto & ri1 = i; 
auto & ri2 = 1; //error

为什么推导类型是 ri1 const int 而不是 ri2?

Why is deduced type of ri1 const int but not ri2?

谢谢!

推荐答案

由于 i 的类型为 const int,而 1 的类型为 <代码>int.

Since i has type const int, but 1 has type int.

这篇关于C++11 中的自动引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆