I have been told that references, when they are data members of classes, they occupy memory since they will be transformed into constant pointers by the compiler. Why is tha
The reference (or pointer) has to be stored in memory somewhere, so why not store it along with the rest of the class?
Even with your example, the parameter a (int &a
) is stored in memory (probably on the stack), then a_ref
doesn't use any more memory, it's just an alias, but there is memory used by a
.