|
Boost : |
From: Greg Colvin (greg_at_[hidden])
Date: 2002-05-04 12:41:49
At 02:14 AM 05/04/2002, you wrote:
>"David B. Held" <dheld_at_[hidden]> writes:
>
>> shared_ptr<FILE> f(p, fclose);
>> shared_ptr<FILE> g(0, fflush);
>
>PMFJI, but I keep wondering why this example keeps reappearing. Both
>fclose() and fflush() have return values that should usually be checked.
>This makes them bad examples for shared pointers with user-specified
>deleter functions IMHO. Or has anybody found a good way for dealing with
>them indicating failure?
No. Since the error comes in the destructor, and since we
don't want destructors to throw, there is often nothing that
can be done about the error. You should wrap these functions
with an error handler (e.g. fclose_or_terminate) if the errors
need handling, but that just clutters up the example.
I like this example because it is a simple case where the
standard library returns a pointer for which delete is
inappropriate.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk