|
Boost : |
From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-01-26 06:53:16
From: "Thomas Maeder" <maeder_at_[hidden]>
> Am 2002.01.25 21:21 schrieb(en) Peter Dimov:
> >
> > Yes, you could (should?) do this
> >
> > shared_ptr<FILE> my_fopen(const char* name, const char* mode)
> > {
> > if (FILE* p = fopen(name, mode))
> > return shared_ptr<FILE>(p, fclose);
> > else
> > throw open_error(name, errno);
> > }
>
> But in general, the success of fclose() should be checked. Can
> shared_ptr be used then?
Should it? What would a program do when fclose fails? shared_ptr's
destructor has a nothrow guarantee.
In any event, shared_ptr<FILE> is not a very good example. I'd define a
separate file class (and the appropriate name for it is std::file IMHO but
that's another story.)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk