13th March 2005
titus:
The C++ way to do this is to wrap access in a class. Put your initialization in the constructor, and the cleanup in the destructor, and then put an object of that class type on the stack.
C++ scope rules will take care of the rest, and it's exception safe.
Hope that helps,