Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

declare typedef type

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?

like image 610
Leonhart Squall Avatar asked Jul 19 '12 10:07

Leonhart Squall


1 Answers

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.

like image 116
Sergey Kalinichenko Avatar answered Oct 22 '22 14:10

Sergey Kalinichenko