小编Sye*_*nun的帖子

如果目标文件已经有头文件保护,我们应该使用#ifndef保护#include吗?

假设我们有两个类,Foo和Bar.

在Foo.h中

#ifndef MYPROJ_FOO
#define MYPROJ_FOO
....
# endif 
Run Code Online (Sandbox Code Playgroud)

在Bar.cpp中,我们还需要保护包括如

#ifndef MYPROJ_FOO
#include <Foo.h>
#endif
Run Code Online (Sandbox Code Playgroud)

还是简单#include 就足够了?如果我们已经有头球防守队员,那么对我来说似乎是多余的,但是我经常看到这样的练习,因此想知道我是否遗漏了什么.谢谢!

c++ macros include-guards c-preprocessor

0
推荐指数
1
解决办法
171
查看次数

标签 统计

c++ ×1

c-preprocessor ×1

include-guards ×1

macros ×1