
2 Nov
2007
2 Nov
'07
11:05 p.m.
Mike Tegtmeyer:
The counter argument that I hear from not-new folks however is that it takes some work to not leak the resource during an exception in the shared_ptr construction. Therefore, the ugliness to maintain integrity diminishes it's usefulness. ie
FILE *in = fopen(...); if(!in) return/throw badness;
//may throw here, 'in' is lost shared_ptr<FILE> fin(in,fclose);
The answer here is much, much easier. 'in' will not be lost. shared_ptr does invoke the deleter when the constructor throws.