相关疑难解决方法(0)

C++中的标题保护程序

LearnCpp.com上| 1.10 - 首先看一下预处理器.在Header guards下,有一些代码片段:

add.h:

#include "mymath.h"
int add(int x, int y);
Run Code Online (Sandbox Code Playgroud)

subtract.h:

#include "mymath.h"
int subtract(int x, int y);
Run Code Online (Sandbox Code Playgroud)

main.cpp中:

#include "add.h"
#include "subtract.h"
Run Code Online (Sandbox Code Playgroud)

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

#ifndef ADD_H
#define ADD_H

// your declarations here

#endif
Run Code Online (Sandbox Code Playgroud)
  • 宣言可以在这里发生什么?而且,应该int main()#endif吗?
  • 是添加_H约定还是必须做的事情?

谢谢.

c c++ macros include-guards header-files

30
推荐指数
3
解决办法
7万
查看次数

标签 统计

c ×1

c++ ×1

header-files ×1

include-guards ×1

macros ×1