|
![](/i/fill.gif) |
Ben Chambers wrote:
> I believe you would create a separate class which inherits from OStream,
> and give it a data member to store the 4 in. You would then define the
> function prettyprintindent(int) to return your subclass. Since it
> inherits, it can still be used like a regular OStream.
Which means you now have two instances pointing to the same stream?
std:cout << pretty(4) << myvalue;
std:cout << myvalue; // No longer pretty(4)?
yadda = (std:cout << pretty(4));
yadda << mine << yours;
// Now what do I do to clean up?
std:cout << pretty(4) << myprettyvalue << magic(15) << mymagicvalue;
// Looks like magic(15) has to understand "pretty" streams?
// Or even
std:cout << pretty(4) << myprettyvalue <<
magic(15) << mymagicvalue
<< pretty(8) << myprettyvalue;
How many copies of the "pretty" value are going to be in the
thing returned by the final << operator?
Fredrik Eriksson wrote:
> Did you not ask this once before?
Yeah, but not I understand other things a bit better, so I'm trying to
figure this one out again. Those links you gave really don't answer the
question, as they seem to be answering too-simple questions.
Ah, I begin to see. ios can allocate a word in each stream specific to
your class.
> Also, look up 'ios::xalloc'.
Ok. It looks like it only works for one integer from one user-defined
type at a time, and if you cast it to a pointer, it still doesn't get
cleaned up when the stream goes out of scope, because there's no type
information. Or am I misunderstanding that? If you allocate (say) a
buffer or something for the stream, at what point does that buffer get
cleaned up?
So it looks like the answer is either "you can't do this with standard
streams" or "for very limited cases it's built into the stream class
already".
--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."
Post a reply to this message
|
![](/i/fill.gif) |