Clean up your #include statements?

后端 未结 12 1304
梦如初夏
梦如初夏 2020-12-05 13:18

How do you maintain the #include statements in your C or C++ project? It seems almost inevitable that eventually the set of include statements in a file is either insufficie

12条回答
  •  北海茫月
    2020-12-05 14:08

    Detecting superfluous includes has already been discussed in this question.

    I'm not aware of any tools to help detect insufficient-but-happens-to-work includes, but good coding conventions can help here. For example, the Google C++ Style Guide mandates the following, with the goal of reducing hidden dependencies:

    In dir/foo.cc, whose main purpose is to implement or test the stuff in dir2/foo2.h, order your includes as follows:

    1. dir2/foo2.h (preferred location — see details below).
    2. C system files.
    3. C++ system files.
    4. Other libraries' .h files.
    5. Your project's .h files.

提交回复
热议问题