Having implemented CLogClass to make decent logging I also defined macro, but it works only with one parameter…
class CLogClass
{
public:
static void DoLog(LPCTSTR sMessage, ...);
};
#define DebugLog(sMessage, x) ClogClass::DoLog(__FILE__, __LINE__, sMessage, x)
Well, it fails when called with more than 2 parameters 🙁 … Is it possible at all to avoid it? Can it be translated to templates somehow?
EDIT: Variadic macros were introduced in VS 2005 (But i'm currently in VS 2003…). Any advices?
Best Solution
You could have a MYLOG macro returning a custom functor object which takes a variable number of arguments.
Note that it's not so hard to step over to the type-safe variant touched by this answer: you don't need any variadic arguments due to the chaining effect of
operator<<
.