Boost logo

Boost :

From: Dietmar Kuehl (dietmar_kuehl_at_[hidden])
Date: 2000-03-07 07:07:48


Hi,

> Basically, the idea is to make a class derived from stringstream
[snip]

Already at this point it is almost certain that it is not such a good
idea: You should not derive from 'std::ostream' or 'std::istream' or
any class derived thereof for a different purpose than convenient
construction and convenient access to a specialized stream buffer.
Instead of deriving from these classes, you normally want to create a
new stream buffer although most people don't seem to be aware of this
fact...

In a derived stream buffer you can direct the character wherever you
want to have them. For example, at
<http://www.fmi.uni-konstanz.de/~kuehl/iostream/> you can find a stream
buffer writing to a GUI window (in this case to a Motif TextWidget but
this can be adapted to other GUI systems quite easily). Although your
approach using a destructor to gather all the output works for some
situations, it does not work that smoothly in others and personally I
prefer to do only clean-up in destructors.

> MyClass() << "This is some output, you can do numbers, too: "
> << hex() << 1234;

Although the compiler I'm using swallows a similar statement without
complaint (using 'std::ostringstream()' rather than 'MyClass'; and the
'hex()' replaced by 'std::hex'), I think this should not compile: The
temporary is bound to a non-const reference when passing it as argument
to 'std::opererator<< (std::ostream&, char const*)'.

__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk