Max Frai
Max Frai

Reputation: 64356

Preprocessor if in c++

I had the following structure:

#if COND
  ...
#endif
#elif COND2
  ...
#else
  ...
#endif

I have to replace elif with two statements: else and if:

#if COND
  ...
#endif
#else
  #if COND2
     ...
  #endif
#else     // error: #else after #else
  ...
#endif

What's wrong?

p.s. No I see what's wrong but how to write it without errors?

Upvotes: 1

Views: 597

Answers (1)

Luchian Grigore
Luchian Grigore

Reputation: 258648

You can't have two #else statements in the same #if.

The correct version would be:

#if COND
  ...
#else
  #if COND2
     ...
  #else
     ...
  #endif
#endif

Upvotes: 2

Related Questions