struct mystruct
{
int i;
double f;
} ;
typedef mystruct myotherstruct;
//the other .cpp file
struct mystruct; //OK,this is a correct forward declaration.
struct myotherstruct; // error C2371(in vc2k8): 'myotherstruct' : redefinition; different basic types
Hi all.
Why can’t I forward declare myotherstruct?
The
myotherstructidentifier is not astructtag, it is a type name in its own rights. You use it without thestructkeyword. Once defined, the name cannot be reused for astructtag. In your example, you are not forward-declaringmyotherstructtype, you are forward-declaring astructwith the tagmyotherstruct, which gives you an error because the namemyotherstructhas already been taken for thetypedef.