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

前端 未结 7 1271
梦谈多话
梦谈多话 2020-12-20 07:18

The exact warning I get is

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

and hand::show is

std::ostr         


        
7条回答
  •  独厮守ぢ
    2020-12-20 08:02

    The warning means it's possible to go through your method without returning any explicit value. With your code:

    std::ostream& hand::show(std::ostream& os) const
    {
        if(side == left)
        {
            return os<

    if side != left and side != right, then you don't return anything. A common way of fixing this problem is to assume, for example, if not "left" then always assume "right":

    std::ostream& hand::show(std::ostream& os) const
    {
        if(side == left)
        {
            return os<

提交回复
热议问题