Reputation: 64905
I have some immutable global objects like so:
const Vehicle Car = ...;
const Vehicle Truck = ...;
...
I need to make "aliases" to these objects, i.e., additional names which refer to the same object.
This seems to work:
const Vehicle& Camion = Truck;
Is it allowed and will it blow up in my face somehow? Will using Camion
be the same as using Truck
, including the object address?
Upvotes: 1
Views: 93
Reputation: 29975
Yes, this is fine.
Reference declaration
Declares a named variable as a reference, that is, an alias to an already-existing object or function.
This is what references are for. They are essentially another name for the same thing. And yes, taking address of a reference gives you the address of the actual variable it is referencing.
Upvotes: 3
Reputation: 78
Yes, you it will be same because the same variable points the same memory address and change in memory address can effect both the variable. https://www.youtube.com/watch?v=Zl-JLUOuyGI
Upvotes: 1