Skip to main content
gamedev.net
🔒 Locked

C circular structs [solved]

Started by Degra May 25, 2006 at 9:34 AM 2 replies 1.3k views
Original Post
Degra
Degra
I can't really think of a way to explain this so I'll use an example:
typedef struct TILE
{
    MONSTER * rootMonster;
} TILE;

typedef struct MONSTER
{
    TILE * startingTile;
} MONSTER;

the structs refer to each other in a circle. The compiler says "syntax error : identifier 'MONSTER'". Is there a way to solve the error? Degra
Nitage
Nitage
You have to tell the compiler that MONSTER is a type before declaring TILE.
Try this:

struct MONSTER;

struct TILE
{
MONSTER* rootMonster;
};

struct MONSTER
{
TILE* startingTile;
};
Alpha_ProgDes
Alpha_ProgDes
typedef struct TILEtypedef struct MONSTER;{    MONSTER * rootMonster;} TILE;typedef struct TILE;typedef struct MONSTER{    TILE * startingTile;} MONSTER;

i believe, but basically you need a forward declaration.
Beginner in Game Development?  Read here. And read here.  

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.