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 myotherstruct identifier is not a struct tag, it is a type name in its own rights. You use it without the struct keyword. Once defined, the name cannot be reused for a struct tag. In your example, you are not forward-declaring myotherstruct type, you are forward-declaring a struct with the tag myotherstruct, which gives you an error because the name myotherstruct has already been taken for the typedef.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With