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
Headers Function how?
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
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
tcache
Contact Me
Formerly known as Wachar <- Thrander <- Tazel
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
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...
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.
//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.
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
tcache
Contact Me
Formerly known as Wachar <- Thrander <- Tazel
tcacheContact Me-----------AH! MY BRAIN IS GOING TO SELF-DETONATE! -- Yours Truly (Jan, 2003)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement