That's what preprocessor commands like #ifdef and #ifndef are for (and no, you can't have logic inside of your class definition unless it's inside a function definition)
-wyrmmage
3DModelerMan wrote:Hi I had a question, why do I never see people use if statements or other logic statements inside classes?, do classes not allow this?.
Thanks .
Presumably you mean inside a class declaration but outside any function definition?
It only makes sense to have executable code inside a function, because otherwise there's no way to call and run the code. So you don't see any code outside of a function (whether global, class static or class instance).
class Foo
{
public:
printf("At what point in your program execution would you expect this code to ever be run?");
Foo()
{
printf("If you want code that's run when an instance is created, put it in the constructor.");
}
};
printf("Or for that matter, how would you run this global code?");