Sign in to follow this  
fishleg003

Problem with header files

Recommended Posts

Hi, Im in same situation as the post below but i tried what fixed his problem but it doesnt seem to work for me basically i have 3 header files A, B, C; A includes B & C B includes nothing C needs to include A so i can use its classes but it wont let me have it :(. Each header has its own unique #ifndef HEADERNAME_H #define HEADERNAME_H ive checked them all over and over but all i get on compile is this, c:\Documents and Settings\Jonesy\Desktop\Level.h(9): error C2011: 'Level_tag' : 'struct' type redefinition If C doesnt include A that error goes but i get alot of level struct undeclared from within the source for header C. thx alot for any help.
Quote:
Heres a post i dug up from way way back in the day sounds like same problem as me. "Can anyone tell me how to get around this problem? I have two different sources that both include the same header file (as well as their own specific headers) because classes in both use the same custom structure. It give's me the error "struct: type redefinition". How should I organize my code to alleviate this problem. Thanks; Prairie"
Quote:
"When you include the same header twice the compiler will treat it has if you have included two different headers and assume that you have done something wrong i.e. defined a structure twice... or something like that. To get around this add the following code to your header file: #ifndef HEADERNAME_H #define HEADERNAME_H . . header stuff struct defn . #endif "

Share this post


Link to post
Share on other sites
Ok good you found it. Just as a tip: I usually type the first line (#ifndef X) and then copy X to the next line (after #define). At least I did before my custom class generator was finished...

Illco

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this