0

My team and I are working on a pretty large project with many classes with their respective header and source files. We are trying to consolidate all includes from both C++ libraries and the projects class header files into one file called "Includes.h" which is included in every header file. One problem I have encountered when doing this is that the class header files are basically including themselves. I have included #pragma once at the top of every header file. When I comment out the #include "Controller.h" in the "#Includes.h" file, the errors for "Controller.h" go away.

Sam
  • 7,252
  • 16
  • 46
  • 65

1 Answers1

3

Please Please Please and Pretty Please do not do this.

Prefer forward declarations. Then the individual include files.

Otherwise you change one include file and it has to compile the lot. I.e. waste of time.

Bascially get each header file to be able to compile with a blank cpp file. Minimum dependecies.

Ed Heal
  • 59,252
  • 17
  • 87
  • 127
  • So better to just include other header files directly in each header? Is there a way to include them all and just exclude the file doing the including from Includes.h? Pretty much all the headers include the rest of the headers. – joekleespies Apr 14 '14 at 20:06
  • @user3516792 - The header file should just use forward declarations. Why include them all when you are not using them? – Ed Heal Apr 14 '14 at 20:08
  • 1
    @user3516792: Please do not use the mammoth include file. It screws up file dependencies for your build system. If one header file is changed, all files must be built including those files that don't use the changed header file. So instead of compiling one file out of 200, the build system will compile all 200. – Thomas Matthews Apr 14 '14 at 20:49
  • Alright thank you all! I ended up going back and putting specific includes in each header and it's working good now. Won't be trying that again! Thanks for all your help! – joekleespies Apr 14 '14 at 22:03