How to use "else if" with the preprocessor #ifdef?

Viewed 2481

In my project the program can do one thing of two, but never both, so I decided that the best i can do for one class is to define it depending of a #define preprocessor variable. The next code can show you my idea, but you can guess that it does not work:

#ifdef CALC_MODE
typedef MyCalcClass ChosenClass;
#elifdef USER_MODE
typedef MyUserClass ChosenClass;
#else
static_assert(false, "Define CALC_MODE or USER_MODE");
#endif

So i can do

#define CALC_MODE

right before this.

I can resign the use of static_assert if needed. How to do this?

1 Answers

Here's a suggestion, based largely on comments posted to your question:

#if defined(CALC_MODE)
    typedef MyCalcClass ChosenClass;
#elif defined(USER_MODE)
    typedef MyUserClass ChosenClass;
#else
    #error "Define CALC_MODE or USER_MODE"
#endif
Related