Unkown type name "Enemy" error after including all headers in C -
i'm developing game sdl 2.0
in c , have following problem: after including needed .h files on each file, compiler shows error (unknown type name 'enemy'
) on shoots.h
, have function parameter of type enemy declared on enemy.h.
the header files think i'm getting error bullet.h, enemy.h, mobs.h, , shoots.h. (there more sdl.h
)
bullet.h
#ifndef bullet_h_included #define bullet_h_included #include "sdl.h" typedef struct bullet *bullet; #endif // bullet_h_included
enemy.h
#ifndef enemy_h_included #define enemy_h_included #include "sdl.h" #include "shoots.h" typedef struct enemy *enemy; #endif // enemy_h_included
mobs.h
#ifndef mobs_h_included #define mobs_h_included #include "enemy.h" typedef struct enemylist *enemylist; typedef struct enemyposition *enemyposition; #endif // mobs_h_included
shoots.h
#ifndef shoots_h_included #define shoots_h_included #include "sdl.h" #include "player.h" #include "bullet.h" #include "enemy.h" typedef struct bulletlist *bulletlist; typedef struct bulletposition *bulletposition; void initenemyshoots(bulletlist l, bulletposition p, player pl, enemy e); #endif // shoots_h_included
struct enemy declaration on enemy.c
struct enemy { sdl_surface *sprite; //enemy sprite int x, y; //enemy position int w, h; //enemy hitbox bulletlist ammo; //enemy bullets };
those headers have declaration of functions implemented on each .c file. structs defined on own .c
that initenemyshoots have problem, since 1 of it's parameters type enemy. how can solve that?
the problem caused #including "shoots.h" in enemy.h
the #include "shoots.h"
comes after #define enemy_h_included
, comes before actual declaration of enemy
pointer struct enemy
. therefore inside shoots.h enemy
not yet defined, enemy_h_included
is, though shoots.h #includes enemy.h, include guards prevent being evaluated , enemy
never gets defined.
the solution not include "shoots.h" inside enemy.h if don't need to.
Comments
Post a Comment