Macro for member function

Discussion in 'C++' started by yoonghm@gmail.com, Sep 20, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Phlip Guest

    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!!!
    Phlip, Sep 20, 2006
    #2
    1. Advertising


  3. > 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
    Frederick Gotham, Sep 20, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Newsgroup - Ann
    Replies:
    5
    Views:
    603
    John Carson
    Jul 30, 2003
  2. slide_o_mix
    Replies:
    0
    Views:
    422
    slide_o_mix
    Oct 15, 2003
  3. Alex
    Replies:
    0
    Views:
    393
  4. 0to60
    Replies:
    4
    Views:
    515
    jeffc
    Nov 21, 2003
  5. Patrick Kowalzick
    Replies:
    5
    Views:
    470
    Patrick Kowalzick
    Mar 14, 2006
Loading...

Share This Page