Hey hey
I'm having some problems with my header files; I've been programming in C++ for awhile now but haven't really had much experience seperating my stuff into cpp and header files.
Anyway, I searched through this forum for a solution and none presented itself, so I'll go ahead and describe my problem.
I put some global declarations into a header file, because of a few of my other cpp files need them.. so I just include the file from the various CPP files. I also put a few function prototypes in the header. Right now I'm just experimenting with two source files including the header - when one source file includes it, everything works fine, and when the other source file includes it everything gets declared twice (I think). I get the errors that all of my globals have already been declared (from the other source, since it already included my header file) but not errors from the function prototypes..
I've written my header in everyway possible to keep things from being declared twice, using the various methods:
#ifndefined myheader_h
#define myheader_h
globals etc.
#endif
and like so:
#if !defined(MAINDEFS_H)
#define MAINDEFS_H
..globals etc.
#endif
But everytime I compile it and have two of my sources include it, everything gets declared twice..maybe there's an inheritence problem I'm not seeing here, like the #define not carrying over to the other source file when it calls the header (I'm not sure if that's possible or not) or something relative to that.. I've looked through many, many people's header files, borlands and microsoft's stuff, they all use methods like this and seem to work, but for some reason it will not work in my project!! GRR!! I'm compiling with MS Visual C++ 6.0 and the project type is a blank win32 app.. maybe I need to use a namespace call or something? I've seen those in various programs but never thought I'd need them..
Anyway anyone who has encountered this please help, I was thinking it was the compiler but tried it on another Visual C++ on another computer at school and it does the same thing. No syntax in my code anywhere or in my header file, so I have no idea why it's declaring the globals twice (maybe the function prototypes as well, but perhaps this doesn't generate an error for some reason).
Thanks to anyone who can help! [sig][/sig]
I'm having some problems with my header files; I've been programming in C++ for awhile now but haven't really had much experience seperating my stuff into cpp and header files.
Anyway, I searched through this forum for a solution and none presented itself, so I'll go ahead and describe my problem.
I put some global declarations into a header file, because of a few of my other cpp files need them.. so I just include the file from the various CPP files. I also put a few function prototypes in the header. Right now I'm just experimenting with two source files including the header - when one source file includes it, everything works fine, and when the other source file includes it everything gets declared twice (I think). I get the errors that all of my globals have already been declared (from the other source, since it already included my header file) but not errors from the function prototypes..
I've written my header in everyway possible to keep things from being declared twice, using the various methods:
#ifndefined myheader_h
#define myheader_h
globals etc.
#endif
and like so:
#if !defined(MAINDEFS_H)
#define MAINDEFS_H
..globals etc.
#endif
But everytime I compile it and have two of my sources include it, everything gets declared twice..maybe there's an inheritence problem I'm not seeing here, like the #define not carrying over to the other source file when it calls the header (I'm not sure if that's possible or not) or something relative to that.. I've looked through many, many people's header files, borlands and microsoft's stuff, they all use methods like this and seem to work, but for some reason it will not work in my project!! GRR!! I'm compiling with MS Visual C++ 6.0 and the project type is a blank win32 app.. maybe I need to use a namespace call or something? I've seen those in various programs but never thought I'd need them..
Anyway anyone who has encountered this please help, I was thinking it was the compiler but tried it on another Visual C++ on another computer at school and it does the same thing. No syntax in my code anywhere or in my header file, so I have no idea why it's declaring the globals twice (maybe the function prototypes as well, but perhaps this doesn't generate an error for some reason).
Thanks to anyone who can help! [sig][/sig]