how to keep track of headers

Hi, I'm asking this because I am reading and "learning" from a book however it does not give me all the information, just enough (hmm) to get me through, and maybe seek online help from if I have to. Is there a proper method of knowing what #includes I should then delete if they become obsolete after another header has it included?? I often find myself getting along with trial and error but I'm sure this is not the answer I seek.

Also should I include some headers in the .h and then later on some in the .cpp, I have found it hasn't caused any problems yet. (maybe include it in the file that needs it, but will still work in the .h??)?

Thanks. Joe D

 
Include headers which contain stuff you need and remove others.

what #includes I should then delete if they become obsolete after another header has it included??
You should always include all headers which you use and do not rely on its inclusion by other headers.

To avoid problems with multiple incluion use header guards, they look like:
1
2
3
4
5
6
#ifndef SOME_UNIQUE_NAME
#define SOME_UNIQUE_NAME

//Header content here

#endif 
Last edited on
Topic archived. No new replies allowed.