Reputation: 189626
My knowledge of C++ arcana is a bit rough. Let's say I have the following classes:
struct Bar {
int x;
};
class Foo {
Bar& bar;
public:
Bar* getRealAddress() { return &bar; }
Foo(Bar& _bar) : bar(_bar) {}
};
Bar bar1;
Foo foo1(bar1);
Will foo1.getRealAddress()
return the same value as &bar1
?
Upvotes: 3
Views: 252
Reputation: 84159
Yes, addresses will be the same since it's the same Bar
instance.
Upvotes: 2
Reputation: 224049
Will
foo1.getRealAddress()
return the same value as&bar1
?
Yes.
Basically, a reference is the original value in all but name. It's an alias.
Upvotes: 11