-
April 19th, 2004, 08:56 PM
#1
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
-
April 19th, 2004, 09:00 PM
#2
yeah, compilers paranoia, go figure...
the compiler expects even a return outside your if-else...
**** **** **** **** **/**
-
April 19th, 2004, 10:00 PM
#3
the culprit is at the while loop. if execution never enter the while loop, then there is nothing to return
-
April 20th, 2004, 12:22 AM
#4
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
-
April 20th, 2004, 07:18 AM
#5
thanks!
i solved it with an unnecessary return
-
April 20th, 2004, 08:01 AM
#6
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
-
April 20th, 2004, 08:12 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|