I need help... I think this could have a simple solution, but i'm not getting ...
I have this following code:
this works fine when i need to use like this
#define PRINT1(s1,s2) printf(s1,s2)
#define PRINT2(s1,s2,s3) printf(s1,s2,s3)
But, now I need to forget the '#defined' and use a global variable to control the PRINT_ME state (because during the execution of my application, i need to change the state of the #define...therefore i can't use #define anymore...i need to use a global variable). And change the PRINT1, and PRINT2 to functions.
PRINT1("Hello number: %d", 1);
PRINT2("Hello both: %d and %d", 1, 2);
Something like this:
I was trying to use templates...because the "printf" function allows any type of variable (%d, %s, %x, %f, etc)..
bool print_me = false;
void setPrint(bool status)
print_me = status;
template < typename T >
void PRINT1(char *s1, T s2)
template <class T, class U>
void PRINT2(char *s1, T s2, U s3)
if(getPrint() == true)
PRINT2("number: %d and %d", 1, 2); //don't work:-(
Any ideias, or a tutorial that can help me accomplish this?