"const int& amp; amp;"和"const int& amp; amp;"之间有什么区别jj"和"int&const jj"? [英] What is the difference between "const int& jj" and "int& const jj"?

查看:74
本文介绍了"const int& amp; amp;"和"const int& amp; amp;"之间有什么区别jj"和"int&const jj"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对两者感到困惑.我知道C ++引用本质上是常量,一旦设置,就无法将其更改为引用其他内容.

I am confused with the two. I am aware of the C++ references which are inherently constant and once set they cannot be changed to refer to something else.

推荐答案

const int& 表示对const int 的引用.(类似地, int& 表示对非常量 int 的引用.)

const int& means reference to const int. (Similarly, int& means reference to non-const int.)

int&const 字面意思是const引用(对非const int ),在C ++中是无效的,因为引用本身无法进行const限定.

int& const literally means const reference (to non-const int), which is invalid in C++, because reference itself can't be const-qualified.

$ 8.3.2/1引用[dcl.ref]

Cv限定的引用格式不正确,除非使用cv限定符通过使用typedef-name([dcl.typedef][temp.param])或decltype-specifier([dcl.type.simple]),在这种情况下cv限定词将被忽略.

Cv-qualified references are ill-formed except when the cv-qualifiers are introduced through the use of a typedef-name ([dcl.typedef], [temp.param]) or decltype-specifier ([dcl.type.simple]), in which case the cv-qualifiers are ignored.

正如您所说,引用本质上是常量,一旦设置,就不能将其更改为引用其他内容.(初始化后,我们无法重新绑定引用.)这意味着引用始终是"const",因此const限定引用或const非限定引用实际上可能没有任何意义.

As you said, references are inherently constant and once set they cannot be changed to refer to something else. (We can't rebind a reference after its initialization.) This implies reference is always "const", then const-qualified reference or const-unqualified reference might not make sense actually.

这篇关于"const int& amp; amp;"和"const int& amp; amp;"之间有什么区别jj"和"int&const jj"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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