c++ - Precompiled Headers in Header Files -


Today I ran into the precompiled header for the first time .. Changing my life again I can not believe that my C + + Code compiling can be fast, it now makes a whole sense ..

Still, one thing that confuses me is that what I have read so far, the pre-compiled headers are the only source Files should be added (CPP?). / P>

In Visual Studio, Project Properties-> C / C ++ - & gt; There is an option under Advanced "Add Force File". I have set that compiler option to stdafx.h .

After doing this ... now let me do my stdafx.h , even my header files (source files are automatically included stdafx.h) Are inside Is this the expected behavior?

I can not find any place in the difference between the header / source files.

If it is good but I'm afraid that it is one of those things that lets you leave VC ++ but break into the GCC. And yes..It should be portable; At least among GCC and VC ++

StdAfx.h should actually be included in source files, not header. I suggest you include "StdAfx.h" first in each CPP and do not use the "Force Include File" option. How can I do this with my cross-platform projects for record, I do not really use precompiled headers in GCC, I make it normally and it works well.

For some background the compiler only appears on the source files (i.e., * .cpp, * .c, etc.) and so when they are compiled, add them to each header and in the header The code found is also compiled. The precompiled header option allows for compiling all the code (i.e., globally included code in StdAfx.h) so that you have to do it all the time. That's what StdAfx.cpp is for. The compiler compiles StdAfx.cpp with all the codes included in StdAfx.h, once you make it instead of making it every time.

Therefore, since you are included as the first item in each source file, it does not mean to include it in any header because it will be included after StdAfx.h and thus All code access is StdAfx.h. Plus you can use other headers in other headers, without worrying about any studfx HH or may include wrong.

Comments