In C ++, one option is to wrap the calls f()and g()in the constructor and destructor of the class and just call these functions creates an instance of an instance of this class. For instance,
struct FAndGCaller
{
FAndGCaller() { f(); }
~FAndGCaller() { g(); }
};
This can then be used in any scope block as follows:
{
FAndGCaller call_f_then_later_g;
}
, , f() g() , .
(SBRM, Resource Assquisition, , RAII) .