B
Bob Altman
Hi all,
I'm hoping someone can suggest a clever way that I can cause a function call
to become a noop when the user builds the Release configuration. Here's the
whole sordid story...
I've created a function that operates like cout except that it directs its
output to a file. Users write to the file using this syntax:
dout << "Text" << number << endl;
Like cout, dout is actually a global variable. The header file that defines
it looks like this (much simplified):
class DebugMessage
{
public:
template <class T> DebugMessage& operator<<(const T& param) {
[implementation] }
}
// Define an external reference to the dout global object
extern DebugMessage dout;
The dll that exposes my DebugMessage class also exports the global dout
object.
Ok, enough background. Now, my issue: I can't just #define dout to make it
go away, because the compiler will choke on the "<< parameters..." part of
the statement. I could create a DebugMessageNoop global object whose "<<"
operator does nothing, and conditionally define dout as either an instance
of DebugMessage or an instance of DebugMessageNoop based on whether the
_DEBUG symbol exists, but that means I need to implement another class and
the callers still get stuck with the overhead of calling into a do-nothing
routine for each "<<" operator.
Is there some way that I can do some #define magic to make the caller's dout
and all of the gibberish to the right of it go away if the _DEBUG symbol
doesn't exist?
TIA - Bob
I'm hoping someone can suggest a clever way that I can cause a function call
to become a noop when the user builds the Release configuration. Here's the
whole sordid story...
I've created a function that operates like cout except that it directs its
output to a file. Users write to the file using this syntax:
dout << "Text" << number << endl;
Like cout, dout is actually a global variable. The header file that defines
it looks like this (much simplified):
class DebugMessage
{
public:
template <class T> DebugMessage& operator<<(const T& param) {
[implementation] }
}
// Define an external reference to the dout global object
extern DebugMessage dout;
The dll that exposes my DebugMessage class also exports the global dout
object.
Ok, enough background. Now, my issue: I can't just #define dout to make it
go away, because the compiler will choke on the "<< parameters..." part of
the statement. I could create a DebugMessageNoop global object whose "<<"
operator does nothing, and conditionally define dout as either an instance
of DebugMessage or an instance of DebugMessageNoop based on whether the
_DEBUG symbol exists, but that means I need to implement another class and
the callers still get stuck with the overhead of calling into a do-nothing
routine for each "<<" operator.
Is there some way that I can do some #define magic to make the caller's dout
and all of the gibberish to the right of it go away if the _DEBUG symbol
doesn't exist?
TIA - Bob