In C++, applying the sizeof operator to a reference type returns the size of the referenced type.
So, I wrote this wrapper class to get the size of the reference type itself:
template <typename T>
struct Ref {
T& ref;
};
and I got that sizeof(Ref<int>) == sizeof(int*); i.e. 4 bytes on a 32-bit architecture, and 8 bytes on a 64-bit architecture.
My questions are:
- Is my assumption that
sizeof(Ref<T>)is the actual size ofT&correct? - If so, am I guaranteed that the size of
Ref<T>(hence ofT&) is the same as the size ofT*for all typesT?