根据 #define 动态编译文件
Dynamically compile files in depending of #define
我有一个项目应用程序,在这个项目中我有两个文件夹"behavior1"和"behavior2"
Application
|_ behaviour1
| |_ action
| |_ action.h
| |_ action.cpp
|
|_ behaviour2
| |_ action
| |_ action.h
| |_ action.cpp
|
|_ behaviour_type.h
|_ app.cpp
其中每个目录中的 action.h 从抽象类定义派生类
class AbstractAction {
public:
virtual ~AbstractAction() = default;
virtual void Execute() = 0;
}
但实现是不同的。
然后通过使用文件"behaviour_type.h"中的下一个代码
#define CURRENT_BEHAVIOUR bevahiour1
#define QUOTEME_1(x) #x
#define QUOTEME(x) QUOTEME_1(x)
#define INCLUDE_FILE(x) QUOTEME(CURRENT_BEHAVIOUR/x)
在"应用程序.cpp"中我可以写
#include "behavior_type.h"
#include INCLUDE_FILE(hook/action.h)
...
AbstractAction* action = new Action();
action->Execute();
但是在这种情况下,将编译两个"action.h"(来自 behavior1 和 behavior2)。我只想编译一个,我把它包括在内。可能吗仅使用源代码(即 my INCLUDE_FILE 指令)编译一个"action.h"文件,而不使用编译器属性。
也许这个问题很傻,对不起,但我是这里的新手。谢谢。
我不知道您的宏做什么或应该实现什么,但为什么不使用简单的变体:
#ifdef ACTION_1
#include "behaviour1/hook/action.h"
#else
#include "behaviour2/hook/action.h"
#endif
AbstractAction* action = new Action();
action->Execute();
也就是说,我完全支持那些说你应该同时拥有两者并使用某种模式而不是条件编译的评论。
相关文章:
- 使用 Makefile 中的头文件编译 Pybind (不使用 cmake)
- 如何使用命令提示符、记事本和 MinGW 使用主文件、头文件和实现文件编译C++程序?
- 无论如何可以将webm / mp4文件编译/记忆为.exe程序吗?(C++)
- 从生成文件编译错误:"Unable to open output file" ..."No such file or directory"
- 如何使用 GLFW 预编译的二进制文件编译 Visual Studio 2019 发布版本
- Arduino IDE中自定义库类的.h文件编译错误的原因是什么
- makefile和错误将与大型项目分开的文件编译
- 如何使用生成文件编译具有多个目录的 c++ 项目
- 我可以将Visual Studio 2015头文件编译成dll并在VS2013中使用它吗?
- 使用Bazel将C 文件编译为python.h
- 使用 .a 文件编译简单的C++文件
- OpenCV 3.2 文件编译
- 如何从多个 cpp 文件编译 WebAssembly
- 从多个文件编译可以"undefined reference"
- 使用静态依赖性为共享二进制文件编译语法需要更加清晰
- 将Gsoap Src文件编译到我的项目中
- 如何用多个文件编译make下的dlib
- 字段的类型不完整,从多个文件编译
- 强制将特定文件编译为Objective-C/文件类型,但将整个项目编译为Objective C++
- OpenGLES 标头(包括 Availability.h)可防止 CPP 文件编译