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
areleft
andright
, so it thinks it's possible for neither return statement to be executed. Whenside
is neitherleft
norright
, your function doesn't say which value to return.