函数重载中的返回类型
请注意,你不能基于其返回类型重载函数。例如:
// WRONG CODE
std::string getValue()
{
return "hello";
}
int getValue()
{
return 0;
}
int x = getValue();
这将导致编译错误,因为即使将返回类型分配给 int
,编译器也无法计算出要调用的 getValue
版本。
请注意,你不能基于其返回类型重载函数。例如:
// WRONG CODE
std::string getValue()
{
return "hello";
}
int getValue()
{
return 0;
}
int x = getValue();
这将导致编译错误,因为即使将返回类型分配给 int
,编译器也无法计算出要调用的 getValue
版本。