Transfer control: GoTo?

This is a discussion on Transfer control: GoTo? within the C++ Programming forums, part of the General Programming Boards category; Hello there, Could I implement goto to transfer control to another function in the class? example: Code: TInt CWrUAppUi::Tick(TAny* aObject) ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    22

    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

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    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.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 08:26 PM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. helpppp
    By The Brain in forum C Programming
    Replies: 1
    Last Post: 07-27-2005, 08:05 PM
  4. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM
  5. Need some help with a basic tic tac toe game
    By darkshadow in forum C Programming
    Replies: 1
    Last Post: 05-12-2002, 05:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21