Topic: does basic_ios::~basic_ios delete its associated streambuf?
Author: James Kanze <james-albert.kanze@vx.cit.alcatel.fr>
Date: 1997/04/14 Raw View
mlg@scr.siemens.com (Michael Greenberg) writes:
|> The december draft does not describe basic_ios::~basic_ios. What does
|> it do (if anything)?
Nothing, I think.
|> Does it delete the associated stream_buf (it there is one)?
It had better not. This would be a major change from existing practice,
and break a lot of my code.
|> The
|> answer is probably no because ~basic_ostream and ~basic_istream
|> explicitly state that they perform no operations on rdbuf().
|> The real question is: If I subclass basic_ostream, and my subclass
|> sets creates a rdbuf(), is my subclass responsible for deleting it?
Supposing it has new'ed it. In most such cases, I just declare the
streambuf a member variable of the derived class, and let the compiler
take care of the rest.
|> Is this correct (ignoring any typos)
|>
|> class foo : basic_ostream<char> {
|> public:
|> foo() : basic_ostream( new my_streambuf ) { }
|> ~foo() { delete rdbuf(); }
|> } ;
If it isn't, there is going to be a lot of broken code out there.
Note that for this to be legal, the guarantee you quote is important:
the destructors of basic_ostream and basic_ios must NOT do anything with
the streambuf; they must not even assume that it exists.
This is not well documented in most of the current iostream
documentation. I count on it only because there is no other way that
things like filebuf could work, and since they do... It is reassuring
to see that it is part of the draft.
--
James Kanze home: kanze@gabi-soft.fr +33 (0)1 39 55 85 62
office: kanze@vx.cit.alcatel.fr +33 (0)1 69 63 14 54
GABI Software, Sarl., 22 rue Jacques-Lemercier, F-78000 Versailles France
-- Conseils en informatique industrielle --
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: mlg@scr.siemens.com (Michael Greenberg)
Date: 1997/04/11 Raw View
The december draft does not describe basic_ios::~basic_ios. What does
it do (if anything)?
Does it delete the associated stream_buf (it there is one)? The
answer is probably no because ~basic_ostream and ~basic_istream
explicitly state that they perform no operations on rdbuf().
The real question is: If I subclass basic_ostream, and my subclass
sets creates a rdbuf(), is my subclass responsible for deleting it?
Is this correct (ignoring any typos)
class foo : basic_ostream<char> {
public:
foo() : basic_ostream( new my_streambuf ) { }
~foo() { delete rdbuf(); }
} ;
Thanks,
--
Michael Greenberg email: mgreenberg@scr.siemens.com
Siemens Corporate Research phone: 609-734-3347
755 College Road East fax: 609-734-6565
Princeton, NJ 08540
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]