Organize includes

后端 未结 6 1127
臣服心动
臣服心动 2020-12-31 00:14
  • Is there some preferred way to organize ones include directives?
  • Is it better to include the files you need in the .cpp file instead of the
6条回答
  •  耶瑟儿~
    2020-12-31 00:57

    (4) I wouldn't recommend to include any additional files into stdafx.h. or similar "include_first.h" files. Direct including into cpp or particular h files allow you to express dependencies of your code explicitly and exclude redundant dependencies. It is especialy helpful when you decide to decompose monolithic code into a few libs or dll's. Personally, I use files like "include_first.h" (stdafx.h) for configuration purpose only (this file contains only macro definitions for current application configuration).
    It is possible to provide precompiled headers for your own files by marking another file to stop precompilation instead of stdafx.h (for instance, you can use special empty file named like "stop_pch.h").
    Note, precompiled headers may not work properly for some kinds of sofisticated usage of the preprocessor (particulary, for some technics used in BOOST_PP_* )

提交回复
热议问题