Clean up your #include statements?

后端 未结 12 1330
梦如初夏
梦如初夏 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:14

    I have the habit of ordering my includes from high abstraction level to low abstraction level. This requires that headers have to be self-sufficient and hidden dependencies are quickly revealed as compiler errors.

    For example a class 'Tetris' has a Tetris.h and Tetris.cpp file. The include order for Tetris.cpp would be

    #include "Tetris.h"     // corresponding header first
    #include "Block.h"      // ..then application level includes
    #include "Utils/Grid.h" // ..then library dependencies
    #include        // ..then stl
    #include     // ..then system includes
    

    And now I realize this doesn't really answer your question since this system does not really help to clean up unneeded includes. Ah well..

提交回复
热议问题