Hi
er****@student.chalmers.se wrote:
What I can tell ostream does not have any constructor taking 0 as an
argument, what were you hoping to accomplish?
How about
"public: explicit basic_ostream(basic_streambuf<char_type, traits>* sb)"?
Anyway, while you can construct this stream, you cannot use it. Outputting
to a stream invokes something equivalent to rdbuf()->sputc(...). Undefined
behavior by dereferencing a null pointer.
>On Dec 13, 1:04 am, isanb...@gmail.com wrote:
>As an added bonus, I'd like to have all cnull symbols and the debug
string removed from the resulting executable when NDEBUG is defined.
Will this happen with the above?
I don't think that this is specified. I might be wrong.
Perhaps you want something like this (I'm not good at macros and it's
untested, but it should give you an idea):
#ifndef NDEBUG
#define DEBUG(x) (std::cerr << x;)
#else
#define DEBUG(x) // not sure about this line, might need () or
something
#endif
Then DEBUG(1 << 4) outputs "1" and then "4"?
People might expect 16.
Another suggestion:
#ifndef NDEBUG
std::ostream& dout = std::cerr;
#else
struct dummy_ostream {
template<typename Tdummy_ostream& operator<< (T) { return *this; }
} dout;
#endif
If you need other members, add them...
Markus