C ++左值引用

所以最近我重新访问了有关类型声明的引用,但我不太理解它们。

考虑以下伪代码:

int ia = 10;
int& ref = ia;

现在,我的问题是:

  1. how do these int& ref work internally, does it mean here that the address of ref is assigned the address of ia and thus equal to &ia if not then what does the compiler do upon seeing these references?
  2. Why aren't these references compiled in a c++ program?

提前致谢。

评论
noptio
noptio

You don't have to think of addresses at all. ref is just another name for ia, or put another way, ref is an alias to ia. Just syntactic sugar for your code.

点赞
评论