By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,745 Members | 1,957 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,745 IT Pros & Developers. It's quick & easy.

Macro for member function

P: n/a
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

Sep 20 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
yoonghm wrote:
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?

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
Sep 20 '06 #2

P: n/a
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

--

Frederick Gotham
Sep 20 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.