I want to write an conditional printf, something like this
class ConditionalPrintf
{
public:
ConditionalPrintf(bool print)
: print_(print)
{}
void printf(int x, double y, char b, const char* format, ...) const
{
// use x, y and b
va_list argptr;
va_start(argptr, format);
if (print_)
printf(format, argptr);
va_end(argptr);
}
private:
bool print_;
};
But it prints garbage. Is there anything wrong? May implicit this parameter change things?
Also, if this isn't good idea whatsoever, what other solutions are there? I just don't want to write if (print) printf(...)
billion times.