I'm working in Visual Studio 2010, using C++ code. What I'm trying to do is change the value of a preprocessor directive during run time, not sure if it's possible but I've tried this..
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
}
How can POO be changed so that class objects use a different implementation of other methods? Or if it's not possible, what's another approach to this?
You seem to be confused about the nature of "preprocessor" directive. These only exist before compiler processing. The compiler eliminates (replaces/processes) macro definitions during the compile step. They don't exist at runtime to change. It's actually a mini-language unto itself that only compiles into c/c++ code, which is then processed by the compiler.
It sounds like you want your class to be two different things based on some sort of runtime input. This may indicate a design problem. You might consider defining two different classes (possibly with a common trivial base class).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With