【发布时间】:2014-09-18 03:16:49
【问题描述】:
我了解错误消息的基本信息;它提醒我,这段代码可能根本不会返回任何东西。但是,我不明白为什么。我的代码很完美,不是吗?
rational operator / (const rational &lhs, const rational &rhs)
{
if(rhs.numerator() != 0)
{
int numerator = lhs.numerator() * rhs.denominator();
int denominator = lhs.denominator() * rhs.numerator();
rational quotient(numerator, denominator);
return quotient;
}
else cout << "error" << endl;
} //this is where error is occurring
【问题讨论】:
-
"控制到达非空函数的末尾[没有在所有执行路径上返回值]"
-
您缺少
return声明。 “我的代码很完美,不是吗?” 离...
标签: c++ function compiler-errors