Can you include other headers in your own header file?

closed account (E3vDSL3A)
For example if I make a header file on Notepad or some thing and add this to it:

1
2
3
4
5
6
7
#include <windows.h>
#include <conio.h>
#include <iostream>
#include <math.h>
#include <allegro.h>
#include <stdlib.h>
#include <time.h> 


...Then won't the preprocessor retrieve the #includes from inside, say, "everything.h" and I'll only need one header to use all of those other ones?


Yep.

-Albatross
closed account (E3vDSL3A)
Yep.


Really? Then how come so many include all of those in their C++ document?
Not sure. Personal preference, I guess. After all, it is one more file to keep track of.

-Albatross
Longer compile times is another deterrant.

Whenever you #include a file, the compiler has to parse it. If you #include dozens of files you don't need, you'll start seeing you compile time increasing.

Plus if you have a "everything.h" file that every file includes -- then every time you change "everything.h"... the entire program needs to be recompiled. For large projects this is huge. I've had several projects that took a good 2 or 3 minutes to fully compile.
closed account (E3vDSL3A)
Why would you need to change "everything.h" though?
I've had several projects that took a good 2 or 3 minutes to fully compile.

Wow, I tend to rely on trial and error, attempting to compile many times before my program works properly. I'll have to change my approach when I get to bigger stuff.
Why would you need to change "everything.h" though?


If you find out you need to use another header, for example.

Wow, I tend to rely on trial and error, attempting to compile many times before my program works properly.


Just recompiling a single source file doesn't take that long. I'm talking about recompiling everything. In a project that's 50+ source files, recompiling all of them takes time.
closed account (E3vDSL3A)
If you find out you need to use another header, for example.


If I only understood that.... ?:(
The headers you mentioned above do not have code for everything you could possibly want.

Later on in your program's development, you might decide you need to use std::string. Since using std::string requires you #include <string>, you have 2 options:

1) put #include <string> in the necessary cpp files

or

2) put #include <string> in "everything.h" and recompile your entire program.
Topic archived. No new replies allowed.