我对C++ arcana的了解有点粗糙.假设我有以下课程:
struct Bar {
int x;
};
class Foo {
Bar& bar;
public:
Bar* getRealAddress() { return &bar; }
Foo(Bar& _bar) : bar(_bar) {}
};
Bar bar1;
Foo foo1(bar1);
Run Code Online (Sandbox Code Playgroud)
会foo1.getRealAddress()返回相同的值&bar1吗?
sbi*_*sbi 11
会
foo1.getRealAddress()返回相同的值&bar1吗?
是.
基本上,引用是除名称之外的所有值的原始值.这是别名.