Leo*_*all 6 c++ typedef declaration
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
Run Code Online (Sandbox Code Playgroud)
大家好.为什么我不能转发声明myotherstruct?
标识符myotherstruct
不是struct
标签,它本身就是一个类型名称。您可以在没有关键字的情况下使用它struct
。一旦定义,该名称就不能重复用于标签struct
。在您的示例中,您不是前向声明类型,而是使用标签myotherstruct
前向声明 a ,这会给您一个错误,因为该名称已被用于.struct
myotherstruct
myotherstruct
typedef