姬長信(Redy)

C和C中的头部守卫


LearnCpp.com | 1.10 — A first look at the preprocessor.在Header guards下,有一些代码片段:

add.h:

#include "mymath.h"
int add(int x, int y);

subtract.h:

#include "mymath.h"
int subtract(int x, int y);

main.cpp中:

#include "add.h"
#include "subtract.h"

在实施头部防护时,提到如下:

#ifndef ADD_H
#define ADD_H

// your declarations here

#endif

>宣言可以在这里发表什么?并且,int main()应该在#endif之后吗?
>将_H添加为约定或必须执行的操作?

谢谢.