Babulesnik
Member
|
Why warning?
I wrote a function:
Code:
Int IndexMOC(Str Socket)
{
FREP(server.clients.elms())
{
if(Equal(server.clients.lockedElm(i).key.asText(),Socket))
return i;
}
}
Get a warning:
Warning 4 warning C4715: 'IndexMOC' : not all control paths return a value c:\documents and settings\дима\рабочий стол\project_fast_games\project\server\server_lib.h 181
|
|
03-15-2011 05:42 PM |
|
Tottel
Member
|
RE: Why warning?
I'm not an expert, but it only returns something (i) when the if statement is true. If it's not, it doesn't return anything, so you may want to return -1 or 0 or something when your if-statement is false.
(This post was last modified: 03-15-2011 05:58 PM by Tottel.)
|
|
03-15-2011 05:58 PM |
|
Chris
Member
|
RE: Why warning?
Add a fail case, and handle it accordingly whenever you call the function - else its not a good coding practice:
[quote='Babulesnik' pid='21907' dateline='1300207339']
I wrote a function:
Code:
Int IndexMOC(Str Socket)
{
FREP(server.clients.elms())
{
if(Equal(server.clients.lockedElm(i).key.asText(),Socket))
return i;
}
return -1;
}
|
|
03-15-2011 06:30 PM |
|
Babulesnik
Member
|
RE: Why warning?
(03-15-2011 06:30 PM)Chris Wrote: Add a fail case, and handle it accordingly whenever you call the function - else its not a good coding practice:
[quote='Babulesnik' pid='21907' dateline='1300207339']
I wrote a function:
Code:
Int IndexMOC(Str Socket)
{
FREP(server.clients.elms())
{
if(Equal(server.clients.lockedElm(i).key.asText(),Socket))
return i;
}
return -1;
}
Thank you very much.
|
|
03-15-2011 07:32 PM |
|