In my daily work, I usually write my code like this:
int ret = 0;
ret = func1();
if(ret != 0) {
return ret;
}
ret = func2();
if(ret != 0) {
return ret;
}
But this means I need to complete a lot of "if(ret!=0){return ret;}",Is there a more C++ elegant implementation to complete the function jump? By the way, we are not allowed to use exception.
The shown code seems to be logically equivalent to:
int ret;
if ((ret=func1()) || (ret=func2()))
return ret;
Tack on as many additional function calls as you wish, in the obvious manner.
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