Is it possible to do a macro selection using something similar to this (wrong) syntax?
#define FLAG MULT
#ifdef FLAG ADD
int op(int a, int b) {return a + b;}
#endif
#ifdef FLAG MULT
int op(int a, int b) {return a * b;}
#endif
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could do this:
However, conditional compilation often leads to sadness (typically, the “unused” branch will end up unmaintained, and things will break when you switch back to using it).
C++ offers better mechanisms (run-time polymorphism, templates, etc.) to solve most (but not all) problems of this nature.