A friend has triggered a series of thinking.

xiaoxiao2021-03-06  65

Const int & ri = i; // ok, reference is not distinguished

Ri ; // error, Ri is constant, not variable

i ; // ok, = = nothing to do with the reference

Ri = b; // error, ri is constant

i = j; // ok, = The variable on the right is independent of the reference

INT & const ri = i; // error, there is no such form, no meaning

He asked me why ri will compile errors, and i will not .ri, I don't all point to the same memory area?

In fact, we can use this variable in IDE, and the compiler is used as a tag or an index. They do not directly represent a memory unit, which is used as an operator. Keyword Const Prefix Description This variable is only read only by the memory cell assigned to it, not that its memory space operating system is not allowed. You can use const_cast <

TYPE-ID> This operator modifies the access permission of the const variable, and the memory space is writable for you!

转载请注明原文地址:https://www.9cbs.com/read-112247.html

New Post(0)