0
someprogram.cpp -----------> #include<string>
     |
     | #include"someheader.h"
     V
someheader.h --------------> #include<string>

what happens if I do this? Is it necessary to include the headers into all files that use them, or can you just go

#include<string>
#include...
#include"someheader.h"
#include"anotherheader.h"

and string and other required headers will be included in the ones below it as well?

4
Contributors
11
Replies
12
Views
8 Years
Discussion Span
Last Post by cikara21
0

You can derive the answer yourself from the fact that #include effectively copies the text of the header file into the cpp file before the compiler starts compiling.

So, my question is: why would you want to require people to follow extra instructions just to use your header file?

0

well, I knew that the include() function in PHP just copied the text from one file into the calling file, but I didn't know if C++ would make the included functions, classes, etc. available only to the scope of the including file.
Is there an issue with including a header in a main module and also in another header? Should I be using #ifndef, etc. directives in all my headers to avoid complications with this?

0

And your origional question seemed to be about whether or not you could include <string> multiples: well all the standard headers use #ifndef too! Cool, right?

0

For the sake of information, are you saying I am wrong about headers, or just spouting your opinion on C++?

Just for the sake of information, are you just refusing to recognize my authority on the coolness of things, or just feeling butthurt about some nonsensical post on the internet?

0

I was just wondering what your "wrong" comment was in response to. If you were saying that standard c++ headers in fact do not use #ifndef statements, that would be important. I see that is not the case.

0

in the source file..u can just go..

#include<string>
#include...
#include"someheader.h"
#include"anotherheader.h"

and remove #include<string> in the "someheader.h"
0

in the source file..u can just go..

#include<string>
#include...
#include"someheader.h"
#include"anotherheader.h"

and remove #include<string> in the "someheader.h"

If you had read any of the previous posts, you would have seen this point:

So, my question is: why would you want to require people to follow extra instructions just to use your header file?

0

If you had read any of the previous posts, you would have seen this point:

I don't have problems with that..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.