Can #if pre-processor directives be nested in C++?

前端 未结 3 1305
孤街浪徒
孤街浪徒 2020-12-04 23:01

I have a question about Pre-processor directives in c++:

For example:

#ifndef QUESTION

//some code here

#ifndef QUESTION

//some code here

#endif
         


        
3条回答
  •  独厮守ぢ
    2020-12-04 23:41

    Yes, we can. The #endif statement matches to the previous #if #ifdef or #ifndef etc for which there hasn't been a corresponding #endif.

    e.g.

    #if  ----------|
    #if  -----|    |
    #endif ---|    |
    #endif --------|
    

提交回复
热议问题