where to write the #include at h or at cpp file

Or not matter?
Where is the correct place to write #include <bla bla>?
At .h file or .cpp file ? or both ?
Thank you
Last edited on
it's nice to post in .h file, because .h is what to be included in all your .cpp files, so you don't have repeat all the #includes in .cpp files.

http://codewall.blogspot.com
Last edited on
Thanks
tonnot wrote:
At .h file or .cpp file ? or both ?
place it where it's needed. Sometimes the order of the includes matters. Mind you that when you change something in a header file that's included like everywhere all that dependend files are compiled as well. Large projects do have their problems with that.
coder777 wrote:
Sometimes the order of the includes matters
Could you give me an example? It doesn't sound right.
The order matters only if the headers are written poorly.

You should only include what's necessary in the header.

tonnot: read section 4, "The Right Way To Include":

http://www.cplusplus.com/forum/articles/10627/#msg49679
Last edited on
Topic archived. No new replies allowed.