Re: Having trouble with streams....
On Aug 10, 9:49 pm, Pete Becker <p...@versatilecoding.com> wrote:
joseph cook wrote:
[...]
On Aug 10, 1:05 pm, SpreadTooThin <bjobrie...@gmail.com> wrote:
Why are you initializing the ostream with 0? Don't you want it
default-constructed?
basic_ostream doesn't have a default constructor. Its only
constructor (in C++03) takes a pointer to a streambuf. Passing
a null pointer is, indeed, a coding error.
Unless that's what you really want? I'm not aware of anything
which forbids the streambuf pointer from being a null pointer;
in fact, the description of function basic_ios<>::init()
explicitly mentions the case, and defines what is supposed to
happen.
Obviously, the constructed object is "unusable" (all input
fails) until you 1) set a valid streambuf, using the non-const
rdbuf(), and 2) clear the error status, but I can imagine that
this might be appropriate in a very few cases (although I've
never encountered one yet). Depending on how the client code
handles errors, it might also be possible to use such an ostream
as a null device.
Be careful inheriting from std::ostream. You can't try and
use this class polymorphically.
Um, std::basic_ostream (ostream is basic_ostream<char>) is the
base class for all the standard library's stream types. It's
intended to be used as a base class for all stream types,
including user-defined ones.
I was going to say... I inherit from it fairly regularly. In
fact, I don't know if I've an application where I didn't inherit
from it at least once.
You haven't posted enough code to be able to say what is the
first thing crashing your code.
Well, maybe. But initializing an ostream subobject with a null
pointer is certainly not a good thing to do.
I suspect that it's not what he wants (but since he doesn't say
what he wants, it's hard to be sure), but as far as the library
goes, it is a valid operation, and certainly shouldn't cause a
core dump.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34