C++ – What does “warning: not all control paths return a value” mean? (C++)

ccontrolswarnings

The exact warning I get is

warning C4715: 'hand::show' : not all control paths return a value

and hand::show is

std::ostream& hand::show(std::ostream& os) const
{
    if(side == left)
    {
        return os<<display[0]<<display[1]<<display[2]<<display[3]<<display[4];
    }
    if(side == right)
    {
        return os<<display[4]<<display[3]<<display[2]<<display[1]<<display[0];
    }
}

where side is a variable of type orientation

orientation{
    left = -1,
    right = 1
};

What does the warning mean, and what would be the best solution to get rid of it?

Best Answer

Your compiler isn't smart enough to take into account that the only two options for side are left and right, so it thinks it's possible for neither return statement to be executed. When side is neither left nor right, your function doesn't say which value to return.