Search code examples
c++return-valuec++builder-5

Function Should Return Value Question


Given a function like so

bool RequestStatus()
{
    ...
    if (code == myCode) {
         return true;
    } else {
         return false;
    }
}

Why would the compiler complain that "Function should return value". Unless I am missing something, how else could it not return true or false? Is it because the value of myCode is runtime dependent so the compiler is not sure on the logical paths?


Solution

  • if you write return (code == myCode); you will save lines, make the compiler happy, and generally be writing in a more C++-ish style.