Include .cpp instead of header(.h)

后端 未结 4 1221
南旧
南旧 2020-12-28 16:46

There are some cases when we include .cpp file instead of standard header file (.h), for example:

#include \"example.cpp\"

instead of

4条回答
  •  感情败类
    2020-12-28 17:25

    There are legitimate uses for #include "impl.cpp":

    1. testing for access to static/etc variables

    2. ad hoc templates like these if c++ template mechanism proves inadequate (rare)

      #define MACRO (...)

      #include "impl.cpp" // uses MACRO

    Note that #include "impl.cpp" can be unsafe it same file is included in separate compilation units that are later linked together.

提交回复
热议问题