【发布时间】:2018-05-26 12:48:14
【问题描述】:
有没有办法通过使用变量作为标头的名称在代码中包含文件?像这样:
const char *ch = "test.h";
/* include it now with the var */ #include ch
如果答案是否定的,是否有任何功能或方法可以做到这一点?
【问题讨论】:
-
没有。包含发生在编译时。
-
不完全符合您的要求,但您可以使用 #if #else #endif 之类的宏以及定义的常量来实现类似的行为
-
This has the feel of an XY problem. 你为什么要这样做?我们或许可以提出替代方案。
-
XY 问题?闻起来很像。