函式過載中的返回型別
請注意,你不能基於其返回型別過載函式。例如:
// 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
版本。