-
including headers
Hi all,
At this point in my C++ life, it seems easy to create a header, in which i put not only definitions and such, but also my other includes.
i.e.
main CPP
Code:
#include "includedh.h"
header
Code:
#include <iostream>
#include <ctime>
other CPP
Code:
#include "includedh.h"
Is this a bad thing to do? If so, why?
-
Bad idea. It makes the program files less convenient to read by requiring the reader to refer to another file -- included.h -- to find out what was included.
Also, you will always have to have the appropriate "included.h" file in the same directory with your main program. Presumably you will have many different "included.h" files, corresponding to various main programs. How will you distinguish one from the other? How do you keep track of which "included.h" goes with which main program.
Or, if you are planning to use the same "included.h" with all of your programs, that's even worse. It means that in many programs you will be including things that didn't need to be included, which means your compiled programs will be bigger than necessary. Furthermore, this is likely to cause conflicts.
-
Thanks for the reply,
I don't do this, i was just curious as to why nobody does.
As to your second point, "includedh.h" was an example name, i wouldn't use a generic name like that. And i definately wouldn't use the same header for different programs.
Your first point is reason enough, i should encourage good habits for when my programs become larger.