c++ For Loop Error

I can't figure out why i keep getting an error on this class member function

Error states "Control may reach end of non-void function".

Error points to the outer curly bracket.

Any help would be greatly appreciated.

---------------------------------------...
1
2
3
4
5
6
7
8
9
bool Mystring:: GreaterThan(Mystring s){ 
for(int i = 0; i < slen; i++){ 
if (s.sval[i] > sval[i]) 
return true; 

else if(s.sval[i] < sval[i]) 
return false; 
} 
}
What happens if s.sval[i] is equal to sval[i]?

I recommend you use one return statement in this function:

1
2
3
4
5
6
7
...
   bool retVal = false;
   if(s.sval[i] > sval[i])
      retVal = true;
...
   return retVal;
}
Topic archived. No new replies allowed.