6
我正在使用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如何更改以便类对象使用其他方法的不同实现?或者如果这是不可能的,另一种方法是什么?
您不能在运行时更改预处理器指令。使用具有不同派生类的基类可能会有效,这取决于您的问题(根据您向我们展示的内容很难分辨)。 – Yuushi