I see so much code including stdafx.h. Say, I do not want pre-compiled headers. And I will include all the required system headers myself manually. In that case is there any other good reason I should be aware of where I require stdafx.h
?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
You can use pre-compiled headers (which are a good thing) without using stdafx.h (I abominate it too). I've only got access to VC++ 6.0 but in that go to Project Settings|C/C++|Precompiled Headers and select "automatic use of precompiled header" but leave the "compiled through" box empty.
Even without pre-compiled headers stdafx.h could be handy as it groups header includes and definitions common for all files.
You can of course choose to repeat all these definitions in every file. stdafx.h is not strictly necessary.
If you don't want to use precompiled headers, then there is no point to using a standard include file - this will slow down the build for every file that includes it and cause them to include extra stuff that they do not need. Get rid of it and just include the headers they need.
As others have mentioned: if you don't need precompiled headers, you don't really need stdafx.h . And using it just to group common includes is pretty bad practice, actually.
In fact, even when using precompiled headers, it's good practice to include the headers your process actually needs after stdafx.h (or precompiled.h or whatever you want to call it) - along with #ifdef magic in your precompiled header to turn off the usage of PCH.
Why? In order to check your module dependencies. Being able to disable your PCH lets you catch whether you're including necessary modules or not, and you can then write a tool to check your module interdependencies by parsing your .cpp and .h files (excluding the PCH header, of course).
I know this is an old thread, but I thought I'd pass my opinion to readers. I found this in 2017, so I'm sure I'm not the only one that will be here.
There is an advantage to using pre-compiled headers, that may be overlooked by others because they have been using their practice for many years. The C++ standard has evolved greatly. Instead of including vector in 20 files that you might need and and or whatever, you use a PCH file and the compiler has to do less work, and that makes happy faces for everyone. Also you can put your common macros in there, such as VERIFY, and ASSERT and smart class objects. Don't put your class headers in there, it wouldn't make sense for that, rather the standard library or something you will need to use globally in a lot of places such as the macros I mentioned.
basically realize this, by including the headers you need in every file you need, such as iostream, string, and vector, you are effectively compiling that every single time as an inline to the file. Include a "Pre Compiled" header, well just the name should ring a bell there.
stdafx.h is just another header file. If you fell you don't need it feel free to not include it and remove it from the project.
However it's quite typical to have a file like stdafx.h exactly for precompiled headers to work and to not include all the stuff manually in each source file.