how to include header files more clearly in C++

前端 未结 3 1592
逝去的感伤
逝去的感伤 2020-12-21 18:08

In C++, I have some header files such as: Base.h, and some classes using Base.h:

//OtherBase1.h
#include \"Base.h\"
class OtherBase         


        
3条回答
  •  清歌不尽
    2020-12-21 18:36

    You have to use header guards to avoid duplication.

    http://en.wikipedia.org/wiki/Include_guard

    For example in your Base.h add following:

    #ifndef BASE_H_
    #define BASE_H_
    
    // stuff in Base.h
    
    #endif
    

    See this SO question for heard guard formats

    #include header guard format?

提交回复
热议问题