"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.