CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Mar 2004
    Posts
    216

    not all control paths return a value

    i loathe that warning.
    ****!!. i can't see why!! can you?

    Code:
    cvehiculo *citerador::obtener_siguiente()
    {
    	if (this->nodo_actual==NULL)
    	{
    		this->nodo_actual=this->lista.get_primero();
    		cvehiculo *vtemp=(this->nodo_actual->get_vehiculo());
    		return vtemp;
    	}
    	else
    	{
    		if (this->nodo_actual!=NULL)
    		{
    			while (this->nodo_actual!=NULL)
    			{
    				this->nodo_actual=(this->lista.obtener_siguiente(this->nodo_actual));
    				if (this->nodo_actual)
    				{	
    					cvehiculo *vtemp=(this->nodo_actual->get_vehiculo());
    					return vtemp;			
    				} 
    				else 
    					return NULL;
    			}
    		}
    		else
    			return NULL;
    	}
    }
    thanks

  2. #2
    Join Date
    Mar 2004
    Location
    Israel
    Posts
    638
    yeah, compilers paranoia, go figure...
    the compiler expects even a return outside your if-else...
    **** **** **** **** **/**

  3. #3
    Join Date
    Apr 2004
    Posts
    6
    the culprit is at the while loop. if execution never enter the while loop, then there is nothing to return

  4. #4
    Join Date
    Mar 2004
    Posts
    137
    Hi,

    Ya, the problem is while loop, if it dose not enters the while loop, ur code dose not have anything to return. Add return statement after while loop.

    Ashish

  5. #5
    Join Date
    Mar 2004
    Posts
    216

    thanks!

    i solved it with an unnecessary return

  6. #6
    Join Date
    Jul 2002
    Location
    Connecticut, U.S.
    Posts
    275
    i solved it with an unnecessary return
    I'm curious, what does the C++ standard say. If I have the following code:

    Code:
    int foo(int i)
    {
        if (i == 1)
            return 1;
        else
            return -1;
    
        return 0;
    }
    Is the "return 0;" statement needed (according the the C++ language standard)?

    Thanks,
    John Flegert

  7. #7
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125
    No, in that case all paths return a value.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured