How to properly name include guards in c++

后端 未结 4 1520
忘掉有多难
忘掉有多难 2021-01-21 08:05

I have 3 header files:

misc.h
MyForm.h
Registration.h

In misc.h file I put

#ifndef MISC_H
#define MISC_H
#endif
4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-21 08:38

    You should use include guards in every header file and nothing should be outside the include guards.

    The name of include guards can be anything as long as it is unlikely to clash with any other name. An example for your MyForm.h might be:

    #ifndef MYFORM_HEADER_
    #define MYFORM_HEADER_
    
    #include "misc.h"
    #include "Registration.h"
    
    /* all code here */
    
    #endif
    

    It is also important that nothing is written outside of the include guards in a header file.

提交回复
热议问题