-
Transfer control: GoTo?
Hello there,
Could I implement goto to transfer control to another function in the class?
example:
Code:
TInt CWrUAppUi::Tick(TAny* aObject)
{
goto repeat;
}
void CWrUAppUi::HandleSessionEventL(...)
{
...
...
repeat:
...
...
}
If not, what are my alternatives?
Thx in advance,
wirefree101
-
At a guess I'd say you can't do that. have you tried it? There are probably some scope issues about it.
Could do something like this:
Code:
class thing
{
private:
int num;
public:
thing( int new_num )
{
std::cout<< "Starting Constructor ... \n";
initialise( new_num );
std::cout<< "Ending Constructor ... \n";
}
void initialise ( int new_num )
{
std::cout<< "Starting Initialiser ... \n";
num = new_num;
std::cout<< "Ending Initialiser ... \n";
}
};
int main( void )
{
thing whatever( 42 );
return 0;
}
Very ... basic example. You can use member functions within classes. Goto's are generally a bad idea. Only real use I've had for them would be for getting out of deep nesting in loops and such. Don't use them often at all.
-
Place everything inside HandleSessionEventL after the repeat label into a new function. Then just call that function from HandleSessionEventL. When inside Tick, call the new function instead of the goto.
That is just a general idea. Each specific case may have a very different solution.