How to properly name include guards in c++

后端 未结 4 1647
忘掉有多难
忘掉有多难 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 09:02

    You need to put individual include guards in every header, notably in MyForm.h:

    #ifndef MYFORM_H
    #define MYFORM_H
    #include "misc.h"
    #include "Registration.h"
    // etc...
    #endif /*MYFORM_H*/
    

    and in Registration.h:

    #ifndef REGISTRATION_H
    #define REGISTRATION_H
    // actual code
    // etc...
    #endif /*REGISTRATION_H*/
    

提交回复
热议问题