Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在运行时更改宏的值 我在Visual Studio 2010中工作,使用C++代码。我试图做的是在运行时更改预处理器指令的值,不确定这是否可行,但我已经尝试过了_C++_Visual Studio 2010_Macros_C Preprocessor - Fatal编程技术网

在运行时更改宏的值 我在Visual Studio 2010中工作,使用C++代码。我试图做的是在运行时更改预处理器指令的值,不确定这是否可行,但我已经尝试过了

在运行时更改宏的值 我在Visual Studio 2010中工作,使用C++代码。我试图做的是在运行时更改预处理器指令的值,不确定这是否可行,但我已经尝试过了,c++,visual-studio-2010,macros,c-preprocessor,C++,Visual Studio 2010,Macros,C Preprocessor,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

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/c++代码,然后由编译器处理


听起来您希望您的类是基于某种运行时输入的两个不同的东西。这可能表明存在设计问题。您可能会考虑定义两个不同的类(可能有一个普通的普通基类)。

不能在运行时更改预处理器指令。将基类与不同的派生类一起使用可能会起作用,这取决于您的问题(从您向我们展示的内容很难判断)。