我的重载函数怎么了?

时间:2019-10-12 03:31:53

标签: c++ overloading

我正在我的课本中练习重载函数,该函数正在2或3个参数中找到最小的数字。但是,我遇到了这样的错误:将功能转换表达式列表视为复合表达式。

我已经通过谷歌搜索尝试了一些方法,但是仍然找不到错误并进行修复。希望您能给出一些指示,谢谢!

double min(double i, double j)
{
    if(i < j)
        return i;
    else
        return j;
}

double min(double i, double j, double k)
{
    if(i < j && i < k)
        return i;
    else if (j < i && j < k)
        return j;
    else
        return k;
}


int main()
{
    double a,b,c;
    cout << "Input the value of a:";
    cin >> a;
    cout << "Input the value of b:";
    cin >> b;
    cout << "Calling min(a,b) for the smallest number : ";
    double(a,b);

    cout << "Input the value of a:";
    cin >> a;
    cout << "Input the value of b:";
    cin >> b;
    cout << "Input the value of c";
    cin >> c;
    cout << "Calling min(a,b,c) for the smallest number : ";
    double(a,b,c);

    system("pause");
}

当我进行编译时,Dev-c ++编译器会给我这样的错误消息:将功能转换表达式列表视为复合表达式。

1 个答案:

答案 0 :(得分:4)

您要调用的是本机类型的“ double”,而不是要重载的函数“ min”。

相关问题