【发布时间】:2013-10-25 03:50:17
【问题描述】:
我正在使用 C++ 代码在 Visual Studio 2010 中工作。我要做的是在运行时更改预处理器指令的值,不确定是否可行,但我已经尝试过了..
somefile.h
static int mValue = 0;
#define POO = mValue;
...
#if POO 0
//define class methods
#else
//define class methods differently
}
main.cpp
main()
{
//Code calls constructor and methods allowed when POO is 0
//Code increments mValue
//Code calls constructor and methods allowed when POO is 1
}
如何更改 POO 以使类对象使用其他方法的不同实现?或者如果不可能,还有什么方法可以解决这个问题?
【问题讨论】:
-
您不能在运行时更改预处理器指令。使用具有不同派生类的基类可能会起作用,具体取决于您的问题(从您向我们展示的内容很难判断)。
标签: c++ visual-studio-2010 macros c-preprocessor