【发布时间】:2011-06-13 14:47:35
【问题描述】:
LearnCpp.com | 1.10 — A first look at the preprocessor。在Header guards下,有那些代码sn-ps:
添加.h:
#include "mymath.h"
int add(int x, int y);
减去.h:
#include "mymath.h"
int subtract(int x, int y);
main.cpp:
#include "add.h"
#include "subtract.h"
在实现header guard时,提到如下:
#ifndef ADD_H
#define ADD_H
// your declarations here
#endif
- 这里有什么声明?而且,
int main()应该在#endif之后吗? - 添加
_H是惯例还是必须做的事情?
谢谢。
【问题讨论】:
-
那么,上面实现的标头gurad是否插入到“add.h”中?
-
我想出了一个更好的保护,当两个类之间存在交叉引用时,避免手动放置前向声明。解决方案在这里:stackoverflow.com/a/56497150/6184124
标签: c++ c macros header-files include-guards