
At 16:56 09.01.2005 +0100, you wrote:
Actually, that try block exists for only the specific case when the constructor throws... I'm not sure how it could be implemented via RAII, as dependencies should only be decremented upon failure. The dtor itself, and thus ReleaseDependency, should not be called if new or the ctor throws.
struct undoer_t { int* value; undoer_t(int* val) value(val) {} ~undoer_t() { if (value) --*value; } void dismiss() { value = 0; } } undoer(&dependents);
..... possibly throwing operation
undoer.dismiss();
Wouldn't it be easier to change AddDependency to something like the following: static void AddDependency ( ) { static bool first = true; if ( first ) { s_inst = static_cast < T * > ( A :: Create ( ) ); dependents = 0; first = false; } ++dependents; } Thomas Beckmann