I want something like this to happen:
void a(){
b()
// if condition met in b(), exit out of this function also
}
void b(){
if(condition){
super return
// also returns out of function a
}
}
I can't seem to think of a way to do this. Any help would be appreciated. Thanks!
Does b has to be void? You could do it normally by:
void a()
{
// if condition met in b(), exit out of this function also
if( !b() )
{
return;
}
//continue...
}
bool b(){
if(condition)
{
return false;
// also returns out of function a
}
return true;
}
There is no way in C++ to do exactly what you ask. There are 4 mechanisms provided by which you can achieve something similar.
Those are your choices. You can write helpers or macros or templates to make them easier to use, but that's what you have to choose from.
Edit: deal with global and return value separately.
Please note that this is a complex topic and there are numerous traps for the unwary, including undefined behaviour using longjmp across a non-trivial destructor. Caveat programmer!
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