problem with "includes"...

Started by
1 comment, last by Zahlman 15 years, 12 months ago
I have this stupid problem which I can't figure out, regarding the inclusion of headers files... I'm starting a medium sized project with multiple cpp and header files. I have one "sys.h" header file that includes all of the headers I need.

#include "input.h"
#include "game.h"
#include "misc.h"
#include "interface.h"
#include "video.h"
#include "display.h"

#include <windows.h>
#include <windowsx.h>
etc' (partial list). On the game header file, I have declared a game data struct.

game.h

typedef struct
{
	*some data variables...*
} gam_data_t;
later on, in the display header file, I've tried using this struct.

display.h

include "sys.h"
void Display(gam_data_t gam_data);
However, for some reason this doesn't seem to work. I get an error: "display.h : error C2065: 'gam_data_t' : undeclared identifier" I'm confused, I'm not sure of the source of this problem, as doing the exact same thing has already worked on different files. Also, if I cut & paste the exact declaration of gam_data_t to a different header file, the compilation returns no error! So I guess it has something to do with the order of the compilation or the include calls, but I'm not sure how to fix that... Thanks for any input!
Advertisement
Quote:I have one "sys.h" header file that includes all of the headers I need.


Don't.

Also, sys.h includes display.h and display.h includes sys.h. This sort of cyclic dependency is not allowed and is possibly what's causing the error. This is another implication of using a "master" header file.
1) Everything Gage64 said.

2) Source file organization FAQ.

3) Would it kill you to spell the word "game" in full?

4) You say you have "cpp" files, implying you are writing in C++. We don't need the 'typedef struct idiom' in C++. The following works perfectly well and is idiomatic:

struct game_data { // why would you put _t at the end?  /* some stuff... */};

This topic is closed to new replies.

Advertisement