Include .cpp instead of header(.h)

后端 未结 4 1223
南旧
南旧 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:42

    I agree with Kerrek SB.

    I did this once. I was building an excellent, widely used compression library that needed to be built separately for 8-bit images and for 12-bit images. The cleanest way I could come up with to fit this into the build system was (oversimplifying a bit) to have two master .cpp files, one that set #defines for an 8-bit build, the other for a 12-bit build. The master .cpp files then #included the source files of the compression library.

    It's okay to not follow a general rule if you understand the rule well enough to know the reasons for it and why it might not apply in your case. (But those cases ought to be rare.)

提交回复
热议问题