I have :
my_entity.h
typedef struct {
long _id;
char *_myEntityType;
char *_myEntitySubType;
long _myEntityGUID;
long _myEntityOwnerGUID;
long _myEntityContainerGUID;
} MyEntity;
typedef struct {
MyEntity *_myEntity;
} MyContainerEntity;
I get the following error when I try running the project:
/my_entity.h: error: conflicting declaration ‘typedef struct MyContainerEntity MyContainerEntity’
} MyContainerEntity;
^
What am I missing, or doing wrong?
Thank you all in advance.
I used a simpler approach (avoid doing multiple steps in a single line with ths structs) and had no problem with the following files:
my_entity.h
struct EntityStruct {
long _id;
char *_myEntityType;
char *_myEntitySubType;
long _myEntityGUID;
long _myEntityOwnerGUID;
long _myEntityContainerGUID;
} ;
typedef struct EntityStruct MyEntity ;
typedef struct {
MyEntity *pointer2MyEntity;
} MyContainerEntity;
main.c
#include <stdio.h>
#include "my_entity.h"
int main()
{
MyEntity firstEntity;
MyContainerEntity containerEntity;
containerEntity.pointer2MyEntity = &firstEntity;
return 0;
}
Alternate content for my_entity.h
typedef struct EntityStruct {
long _id;
char *_myEntityType;
char *_myEntitySubType;
long _myEntityGUID;
long _myEntityOwnerGUID;
long _myEntityContainerGUID;
} MyEntity ;
typedef struct {
MyEntity *pointer2MyEntity;
} MyContainerEntity;
OK , I admit I got it wrong, I thought it was necessary to have a separate distinct name for the struct, but even the code that the OP gives works (I did not test it initially, because I went up editing it and tested my version only). So since he does not give full files for the .h and for main(), I guess we cannot help him.
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.