Declare typedef

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 

Hello everybody. Why can't I forward myotherstruct ad?

+6
source share
2 answers

The myotherstruct identifier myotherstruct 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 the struct tag. In your example, you do not specify the type myotherstruct forward-declaring myotherstruct , you are forwarding a struct with the myotherstruct tag, which gives you an error, since the name myotherstruct has already been taken for typedef >.

+1
source

You cannot forward declare typedefs without the direct struct declaration that was printed. You must first send a struct declaration and then typedef

 struct mystruct; typedef mystruct myotherstruct; 
+1
source

Source: https://habr.com/ru/post/920878/


All Articles