I want to execute some function right before the return of another function. The issue is that there are multiple returns and I don't want to copy-paste my call before each of them. Is there a more elegant way of doing this?
void f()
{
//do something
if ( blabla )
return;
//do something else
return;
//bla bla
}
I want to call g() before the function returns.
struct DoSomethingOnReturn {
~DoSomethingOnReturn() {
std::cout << "just before return" << std::endl;
}
};
...
void func() {
DoSomethingOnReturn a;
if(1 > 2) return;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With