Got a bit confused about this error I'm getting ...
So, in this code snippet, I have 2 structs :
typedef struct
{
char *cMake;
model *testModel;
} make;
typedef struct
{
char * cModel;
} model;
Now, if I compile, I receive the following errors :
Error 1 error C2061: syntax error : identifier 'model'
Error 2 error C2059: syntax error : '}'
If I comment the model *testModel
line, it compiles fine ... Any ideeas ? Thank you !
Declare model
type before make
:
typedef struct
{
char * cModel;
} model;
typedef struct
{
char *cMake;
model *testModel;
} make;
Generally an identifier name cannot be used before it has been fully declared.
order!
typedef struct
{
char * cModel;
} model;
typedef struct
{
char *cMake;
model *testModel;
} make;
your compiler doesn't know model when you use it, because it's defined later in the code.
You should declare model
before tring to use it. The simplest way to do that in this case is to simply swap the two definitions around.
You could also forward declare model
and leave the order the same but that's unnecessary here.
If you define model first, it works well.
typedef struct
{
char * cModel;
} model;
typedef struct
{
char *cMake;
model *testModel;
} make;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.