how to include header files more clearly in C++

前端 未结 3 1591
逝去的感伤
逝去的感伤 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:38

    To avoid having problems related to importing the same header file more than once, you can use the preprocessor to guard against that. The usual way of doing this is by adding these bits to Base.h:

    #ifndef BASE_H_CONSTANT
    #define BASE_H_CONSTANT
    
    // Stick the actual contents of Base.h here
    
    #endif
    

提交回复
热议问题