lundi 24 août 2015

c++ preprocessor conditional parameter [duplicate]

This question already has an answer here:

Please note c++03! any c++11 solutions are not good for me, but do post them just for knoledge sake

I know the preprocessor can do things like

#define FOO 4
#if FOO == 4
    cout<<"hi"<<endl;
#endif

What I need is

#define BAR(X)\
    #if X == 4\
       cout<<"hi"<<endl;\
    #endif

main.cpp

BAR(4)

I don't see why all the needed information wouldn't be available in preprocessor time.

Please tell me how to do this correctly, or why this isn't possible and how to bypass it.


edit 1: A normal if condition won't work for my case, because I also do things like

#define BAR(X)\
    #if X == 4\
       int poop;
    #elif
       double poop;
    #endif

Thanks

Aucun commentaire:

Enregistrer un commentaire