A Note on Pointer and Reference Parameters
It is your responsibility to ensure that any parameters that are bound to the scope guard continue to exist at least as long as the scope guard itself. If a parameter bound to the scope guard is destroyed and the scope guard is not dismissed before the end of the local scope, the behavior of the program is undefined. Example:
// ...
void deref_print_string(const RWCString* pstr) {
printf ("%s\n", pstr->data());
}
// ...
RWCString* pstr = new RWCString("hello world!");
RWScopeGuard sg = rwtMakeScopeGuard(deref_print_string, pstr); //1
delete pstr; //2
pstr = 0;
sg.dismiss(); //3
Note that this is not a problem for values, but is important to be aware of when passing a pointer or reference to the rwtMakeScopeGuard() function.