stdafx.h: When do I need it?

后端 未结 6 707
不思量自难忘°
不思量自难忘° 2021-01-01 10:08

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 m

6条回答
  •  南方客
    南方客 (楼主)
    2021-01-01 10:33

    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).

提交回复
热议问题