Macro for member function

Y

yoonghm

Hi:

I have a large piece of C++ source code that make use of cout
function to perform run-time trace. Due to performance issues, I would
like to turn off the it from the compilation. However, I do not want to
change each of the source code but only the trace functions. For
example,

int
main()
{
TRACE::Show(xxxx)
...
}

In the trace.h:

Class TRACE
{

public: Show(xxxx);

}

In the trace.cc

TRACE::Show(xxx)
{

}

Any example to use macro to define the Show(xxx) to none from the
trace.cc or trace.h?

Regards
Yoong
 
P

Phlip

yoonghm said:
I have a large piece of C++ source code that make use of cout
function to perform run-time trace. Due to performance issues, I would
like to turn off the it from the compilation. However, I do not want to
change each of the source code but only the trace functions. For
example,
TRACE::Show(xxxx)

/The C++ Programming Language, 3rd Edition/, by Bjarne Stroustrup, has a
perfect example of this, with a template. Could someone whip it out, please?
 
F

Frederick Gotham

I have a large piece of C++ source code that make use of cout
function to perform run-time trace.


"cout" is a global object -- not a function.

Due to performance issues, I would
like to turn off the it from the compilation. However, I do not want to
change each of the source code but only the trace functions. For
example


Maybe something like the following:

class CoutManipulator {
public:
template<class T>
CoutManipulator &operator<<(T const&) {return *this;}

template<class T>
CoutManipulator const &operator<<(T const&) const {return *this;}
} coutmanipulator;

#define cout coutmanipulator

/* Code goes here */

#undef cout
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top