Naming Include Guards

前端 未结 9 1238
忘了有多久
忘了有多久 2020-11-29 08:37

How are C++ include guards typically named? I tend to see this a lot:

#ifndef FOO_H
#define FOO_H

// ...

#endif

However, I don\'t think

9条回答
  •  失恋的感觉
    2020-11-29 08:52

    Look at the code that #include's your header.

    If it is something like:

    #include "mylib/myheader.h"
    

    mylib/myheader.h is already a unique name. Just capitalize and replace / and . with _

    #define MYLIB_MYHEADER_H
    

    If you have two headers on your include path with the same name relative to the include path, you already have a collision at that level.

提交回复
热议问题