Reference takes it’s own space in memory.

class A
{
   public:

      int &x;
      int y;

   public:

      A(): x(y), y(0) {};
      ~A() {}
};

int main( int argc, char** argv )
{
   A a;
   cout << sizeof(a) << endl;
   return 0;
}

출력결과: 12 (Linux x64에서 테스트)

Reference takes it’s own space in memory.
We must always initialize the Reference member variable of a Class in it’s Initialization List of it’s constructor.
Else there will be a compilation error!! 
error: uninitialized reference member

Add a Comment