【问题标题】:Will C++ preprocessor deals with the content of a h file which is included by my current h file [duplicate]C ++预处理器是否会处理我当前的h文件中包含的h文件的内容[重复]
【发布时间】:2019-01-08 02:06:04
【问题描述】:

例如: 在 my.h 文件中,我包含了 nest1.h

#ifndef MY_H
#define MY_H

#include nest1.h
...
some_function_declaration
...
#endif

在nest1.h中,我包含了另一个h文件nest2.h

#ifndef NEST1_H 
#define NEST1_H

#include nest2.h
...
#endif

nest2.h

#ifndef NEST2_H
#define NEST2_H

int foo();
#endif

预处理器会将 foo() 复制到 my.h 中吗?我可以在 my.cc 文件中使用 foo() 吗? 如果nest2.h包含nest3.h,my.cc可以使用nest3.h中的函数吗?为什么? 如果有人知道答案,也请链接相关文章。谢谢!

【问题讨论】:

  • 有些编译器有一个选项可以查看预处理后的结果,g++是-E

标签: c++


【解决方案1】:

是的,包括传递性工作。

您可以递归地包含 [几乎] 任意数量的标题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-26
    • 1970-01-01
    • 2019-06-22
    • 1970-01-01
    • 2010-12-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多