• Announcements

Archived

This topic is now archived and is closed to further replies.

Recommended Posts

Tazel    122
When you have something in a header like a class, can you use the public members of it if you just include it on the top of the source file?
tcache Contact Me
Formerly known as Wachar <- Thrander <- Tazel

Share on other sites
Tazel    122
Also, can we just write the code as we would normally in the header files or do we need some #define or something?

tcache
Contact Me

Formerly known as Wachar <- Thrander <- Tazel

Share on other sites
The #include directive works by taking the contents of the header file and putting them in the place of the call to the #include directive. For example...

  //Whatever.henum EYE_COLOR{EC_BROWN,EC_GREEN,EC_BLUE};struct PERSON{char Name[256];int Age;EYE_COLOR EyeColor;};//Whatever.cpp#include "Whatever.h"int main(){//...

  //Whatever.cpp, when run through the preprocessor is converted to:enum EYE_COLOR{EC_BROWN,EC_GREEN,EC_BLUE};struct PERSON{char Name[256];int Age;EYE_COLOR EyeColor;};int main(){//...

So, to answer your question, yes, you can, seeing as how it will just be as if it were defined at the top of the program at linking time. You have to be careful though, if you defined an instance of the PERSON object, for example, you''d be in trouble because the global would be defined multiple times if you included it in multiple source modules. Also, if you recursively include things, it can lead to further complications.

Share on other sites
Tazel    122
Ok thanks. Also, is it better to initialize headers like windows.h in the header file and just include your one own header file or just initialize all of the windows headers in the cpp file?

tcache
Contact Me

Formerly known as Wachar <- Thrander <- Tazel