Hallo!

I want to debug my programm (e.g. a C++ DLL) by using my own CDebugOut class which has overloaded >> operators (like std::cout does) to output differnt types of variables and add a timestamp.

In the file stdafx.h I have defined following defines:


#ifndef _DEBUG_RELEASE
#define _DEBUG_RELEASE

#include "DebugOut.h"

extern class STSRV::CDebugOut *oLog;

#define _STSRV_DEBUG_OUT (*oLog)
#define _STSRV_DEBUG_OUT_ENDL \
"\n"; oLog->print();

// *** Ausgabe hex/dez bei
#define _COUT_DEC (*oLog).dec();
#define _COUT_HEX (*oLog).hex();

#endif // _DEBUG_RELEASE





In the code I am using the code like this:

_STSRV_DEBUG_OUT << "Variable x = " << x << _STSRV_DEBUG_OUT_ENDL;



These defines has the advantage that the define _STSRV_DEBUG_OUT or _STSRV_DEBUG_OUT_ENDL can be defined as std::cout or std::endl or even as std:fstream or what ever you like.

The problem is following: This defines should only be available in Debugmode. I tried to declare the define _STSRV_DEBUG_OUT as following:


#define _STSRV_DEBUG_OUT \
#ifdef _DEBUG \
(*oLog)

#define _STSRV_DEBUG_OUT_ENDL \
"\n"; oLog->print(); } \
#endif // _DEBUG





But I get compiler error if I use a second precompiler directive in a macro or define.
Is it not allowed to use a second precompiler command in a macro?

The compiler errors are following:
error C2121: '#' : invalid character : possibly the result of a macro expansion
error C2065: 'ifdef' : undeclared identifier
....

Thanx for your help!