S
subramanian100in
Consider the program:
class Test;
class First
{
Test t_obj;
};
int main()
{
return 0;
}
If I compile, I get compilation error for the line
Test t_obj;
because Test class is not defined.
My doubt is the following:
Since I am not creating an object of class First, why doesn't the
compiler allow me to have an object of incomplete type(here Test) as
data member ? If an object of type First is created, then the compiler
will need to know the size of the object and in turn it needs to know
the size of each data member. Here no object is created.
I am unable to understand the reason. Where am I going wrong ? Kindly
explain
Thanks
V.Subramanian
class Test;
class First
{
Test t_obj;
};
int main()
{
return 0;
}
If I compile, I get compilation error for the line
Test t_obj;
because Test class is not defined.
My doubt is the following:
Since I am not creating an object of class First, why doesn't the
compiler allow me to have an object of incomplete type(here Test) as
data member ? If an object of type First is created, then the compiler
will need to know the size of the object and in turn it needs to know
the size of each data member. Here no object is created.
I am unable to understand the reason. Where am I going wrong ? Kindly
explain
Thanks
V.Subramanian