3 ms·
> I don't know what you mean by "really pass-by-reference". I was wondering if `int &a2 = a;` allocates memory in stack to make `a2` refer to `&a`, or does `a2
by ThoAppelsin 8y ago
> I don't know what you mean by "really pass-by-reference".
I was wondering if `int &a2 = a;` allocates memory in stack to make `a2` refer to `&a`, or does `a2` somehow truly become an alias for `a` in symbol table. As you've said that the assembly would look the same as pointers being dereferenced, then I suppose C++'s reference types are just a syntax sugar around the C's way of achieving the pass-by-reference concept through passing the address and then dereferencing it.
- chi3 8y agoUnless I'm misunderstanding you, what you're asking is only possible in a function signature if the compiler inlines it. However, outside of function signatures, if you write: int a = 2; int &aref = a; int b = aref; I'd assume that the compiler is smart enough to optimize away &aref.