Choosing between a Null stream and ostringstream

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Naveen Akarapu
    New Member
    • Aug 2010
    • 1

    #1

    Choosing between a Null stream and ostringstream

    #define LOG(level) \
    (level > Log::CurrentLev el() ? NullStream(): Log().Get(level ))

    struct NullStream:std: :ostream {
    public:
    NullStream():st d::ios(0), std::ostream(0) {}
    };

    Log().Get() returns a ostringstream.

    The following statement statement gives the below compiler error:
    LOG(3) << "logging" << endl;


    error: operands to ?: have different types ‘NullStream’ and ‘std::basic_ost ringstream<char , std::char_trait s<char>, std::allocator< char> >’

    How can I rewrite the Macro LOG?


    Thanks
    Naveen
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    What are you trying to do?

    The first hint of trouble is that #define. You use those in C a lot but rarely in C++.

    Comment

    Working...