Click here to Skip to main content
15,919,931 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Header files #include problem Pin
David Crow3-Nov-07 11:56
David Crow3-Nov-07 11:56 
AnswerRe: Header files #include problem Pin
Bram van Kampen3-Nov-07 12:39
Bram van Kampen3-Nov-07 12:39 
GeneralRe: Header files #include problem Pin
Oliver1233-Nov-07 13:58
Oliver1233-Nov-07 13:58 
GeneralRe: Header files #include problem Pin
Peter Weyzen3-Nov-07 19:13
Peter Weyzen3-Nov-07 19:13 
GeneralRe: Header files #include problem Pin
Vaclav_4-Nov-07 5:30
Vaclav_4-Nov-07 5:30 
GeneralRe: Header files #include problem Pin
Peter Weyzen4-Nov-07 6:36
Peter Weyzen4-Nov-07 6:36 
GeneralRe: Header files #include problem Pin
Bram van Kampen4-Nov-07 11:49
Bram van Kampen4-Nov-07 11:49 
GeneralRe: Header files #include problem Pin
Bram van Kampen4-Nov-07 11:11
Bram van Kampen4-Nov-07 11:11 
Your compiler reads your source file line by line. the #include directive means exactly that: 'include' It is conceptually as if at that point the entire file to be included is copied and pasted to the location of the #include directive. What the compiler digests is your cpp file, with at all levels the #include directives removed and replaced by the contents of the file to be included. This is one of the functions of the Pre-Processor. (Note that the compiler proper knows nothing about header files, it compiles the cpp file after the Pre-Processor has expanded it.) So, the ordering of things depends on the ordering of your #include file directives, and on the order of the statements in your header files.

Similar Sample with Line Numbers:

1  class X;<br />
2  class Y{<br />
3   X* m_pX;<br />
4  };<br />
5  class X{<br />
6   Y* m_pY;<br />
7  };


The Class X is forward declared at line 1
The forward Declaration is used in line 3
The Class Declaration for class Y is completed on line 4
The Class Declaration for class X starts on line 5;
The Class declaration for class X uses class Y on line 6.This can be done without a forward declaration, because class Y is fully declared after line 4.
The Class Declaration for X completes at line 7.
If you try to do anything of the kind of *m_pX before the end of line 7 you get an error, you dereference something that has not been completely declared.

Hope this clarifies things.

N.B. A Note about '#pragma once'
It is not difficult to end up with a 'spagetti' of include files, and at some stage inevitibly a file would be included twice. This gives all sorts of problems, and the compiler usually chokes on this, but this situation is often hard to unravel.
The directive '#pragma once' tells the preprocessor to check if the particular file has already been included, and, if so to ignore the #include directive.

Best of Luck Smile | :)

Bram van Kampen

GeneralRe: Header files #include problem Pin
Oliver1234-Nov-07 11:33
Oliver1234-Nov-07 11:33 
GeneralRe: Header files #include problem Pin
Bram van Kampen4-Nov-07 12:17
Bram van Kampen4-Nov-07 12:17 
GeneralRe: Header files #include problem Pin
Oliver1235-Nov-07 14:23
Oliver1235-Nov-07 14:23 
Question4 bit datatype? Pin
_NielsB3-Nov-07 8:56
_NielsB3-Nov-07 8:56 
AnswerRe: 4 bit datatype? Pin
David Crow3-Nov-07 11:55
David Crow3-Nov-07 11:55 
GeneralRe: 4 bit datatype? Pin
Bram van Kampen3-Nov-07 13:04
Bram van Kampen3-Nov-07 13:04 
QuestionChanging resource in a dll Pin
Imtiaz Murtaza3-Nov-07 8:14
Imtiaz Murtaza3-Nov-07 8:14 
AnswerRe: Changing resource in a dll Pin
Peter Weyzen3-Nov-07 18:58
Peter Weyzen3-Nov-07 18:58 
QuestionRemoving the scrollbars from a CFormView derived class Pin
Sternocera3-Nov-07 7:17
Sternocera3-Nov-07 7:17 
AnswerRe: Removing the scrollbars from a CFormView derived class Pin
Nelek4-Nov-07 21:36
protectorNelek4-Nov-07 21:36 
GeneralRe: Removing the scrollbars from a CFormView derived class Pin
Sternocera4-Nov-07 22:05
Sternocera4-Nov-07 22:05 
GeneralRe: Removing the scrollbars from a CFormView derived class Pin
Nelek4-Nov-07 23:48
protectorNelek4-Nov-07 23:48 
Questionflexgrid or any grid VC++ 2003 Pin
Rhymhoont3-Nov-07 6:30
Rhymhoont3-Nov-07 6:30 
QuestionTimer Triggers Pin
thes3cr3t13-Nov-07 4:56
thes3cr3t13-Nov-07 4:56 
AnswerRe: Timer Triggers Pin
Nelek7-Nov-07 4:01
protectorNelek7-Nov-07 4:01 
QuestionCreateProcess returns Error 1450 - No sufficient resources to complete requested service Pin
vipin_nvk3-Nov-07 4:52
vipin_nvk3-Nov-07 4:52 
AnswerRe: CreateProcess returns Error 1450 - No sufficient resources to complete requested service Pin
bob169723-Nov-07 6:40
bob169723-Nov-07 6:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.