A
Anunay
Hello all,
I have a doubt regarding references. Consider the following program:
class Test
{
int &i;
int &j;
int &k;
};
int main()
{
cout<< "size of class Test = " << sizeof(class Test) <<endl;
return 0;
}
On my machine. this prints 12 i.e size of 3 pointers. What i know about
references is that, we need to initialize them at the time of
declaraion. But, here we are not doing so. We are not defining a
constructor also. I was expecting a compilation error saying that I
need to initialize i,j and k. But instead, I got 12!
Kindly explain this behaviour.
Thanks,
Anunay
I have a doubt regarding references. Consider the following program:
class Test
{
int &i;
int &j;
int &k;
};
int main()
{
cout<< "size of class Test = " << sizeof(class Test) <<endl;
return 0;
}
On my machine. this prints 12 i.e size of 3 pointers. What i know about
references is that, we need to initialize them at the time of
declaraion. But, here we are not doing so. We are not defining a
constructor also. I was expecting a compilation error saying that I
need to initialize i,j and k. But instead, I got 12!
Kindly explain this behaviour.
Thanks,
Anunay