Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!lll-winken!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!att!westmark!mole-end!mat From: mat@mole-end.UUCP (Mark A Terribile) Newsgroups: comp.lang.c++ Subject: Re: Deriving new stream types: tstream Summary: Virtual isn't virtuous Message-ID: <478@mole-end.UUCP> Date: 3 Feb 91 07:34:16 GMT References: <48695@apple.Apple.COM> Organization: mole-end--private system. admin: mole-end!newtnews Lines: 34 > > Clearly, in order to get the functionality of an ostream, I need to > > inherit from ostream, but since an ostream has data, I can only contain > > one ostream; I now have an assymetry between the two ostreams which are > > being printed to: one is a base class and one is a member. Also, why > > don't all the output functions defined on ostream resolve to calling a > > single function, like "put"? That surely would have made inheriting > > from ostream much simpler. > > The ostream class is practically useless as a base class since all of the output > operators are non-virtual. I have asked on this newsgroup before why aren't > the output operators virtual? I received no answers. First, the operators are not virtual because it would have imposed the cost of virtual function call on every character, defeating the benefits of bufferring the output. Realize that there are two different categories of output on ostream s. Output via the insert operator is ``formatted,'' output via the functions is ``unformatted.'' They former is subject to a variety of control flags and other goodies; the latter is not. The key point in the stream is its interface to the streambuf. I certainly don't claim that it's intelligible; only that you need to do your magic stuff BENEATH that interface and inside the streambuf. What you need is a streambuf whose flush function sends its output to two other streambufs, those other streambufs representing where you want the output to go. It's the streambuf, not the stream, from which you need to derive. -- (This man's opinions are his own.) From mole-end Mark Terribile