M
Milind
Hi,
I was trying to implement a composition relation, somthing of the
following type:
class A
{
public:
class B
{
int member_of_B;
};
B b;
// ... some other members;
};
but as the defintion of B is too large I thought of may be writing it
outside. . So i modified the class as:
class A
{
class B;
B b;
....
};
class B {
int member_of_B;
};
We have two issues here:
1. anybody including "the .h" (in which i have declared the classes)
would get the type B and can use it. which i didn't intend to allow .
2. gcc 3.3.2 gave me an error of this type:
error: field `b' has incomplete type
Am I not allowed to use forward referencing ? What exactly does the
statement
class B;
in definition of A do? Doesn't it introduce the typename in A?
Any suggestions? Am I missing something obvious ?
~ M.
I was trying to implement a composition relation, somthing of the
following type:
class A
{
public:
class B
{
int member_of_B;
};
B b;
// ... some other members;
};
but as the defintion of B is too large I thought of may be writing it
outside. . So i modified the class as:
class A
{
class B;
B b;
....
};
class B {
int member_of_B;
};
We have two issues here:
1. anybody including "the .h" (in which i have declared the classes)
would get the type B and can use it. which i didn't intend to allow .
2. gcc 3.3.2 gave me an error of this type:
error: field `b' has incomplete type
Am I not allowed to use forward referencing ? What exactly does the
statement
class B;
in definition of A do? Doesn't it introduce the typename in A?
Any suggestions? Am I missing something obvious ?
~ M.