What is "sentry object" in C++?
- by Romain Hippeau
I answered this question, and Potatoswatter answered too as
The modern C++ equivalent would be a
sentry object: construct it at the
beginning of a function, with its
constructor implementing call(), and
upon return (or abnormal exit), its
destructor implements
I am not familiar with using sentry objects in C++.
I thought they were limited to input and output streams.
Could somebody explain to me about C++ sentry objects as well as how to use them as an around interceptor for one or more methods in a class ?
i.e. How to do this ?
Sentry objects are very similar
indeed. On the one hand they require
explicit instantiation (and being
passed this) but on the other hand you
can add to them so that they check not
only the invariants of the class but
some pre/post conditions for the
function at hand.