-1

我正在尝试制作一个带有重载函数“显示”的程序。到目前为止我还好,但我似乎被困住了。我似乎无法弄清楚我在这里的代码做错了什么。

#include <iostream>
#include <iomanip>
using namespace std;
int main()


{
    double small_num, large_num;
    double display;//I think the problem is here!!!

    cout <<"Please enter two number starting with the smallest, then enter the      largest"<<endl;

cin >> small_num;
cin >> large_num;
display(small_num, large_num);



system("pause");
return 0;
}

void display(int num1, int num2)
{
    cout << num1 <<" "<< num2 << endl;
    return;
}

void display(double num1, int num2)
{
    cout << num1 <<" "<< num2 << endl;
}

void display(int num1, double num2)
{
    cout << num1 <<" "<< num2 << endl;
}

void display(double num1, double num2)
{
    cout << num1 <<" "<< num2 << endl;
}
4

1 回答 1

0

删除double display;. 这会创建一个名为 的新局部变量display,它与您的函数名称冲突。

还有:

  • display方法放在上面main
  • 将它们的定义保留在原处并在 main 上方声明它们,如下所示:

    void display(int num1, int num2);
    void display(double num1, int num2);
    void display(int num1, double num2);
    void display(double num1, double num2);
    
于 2013-09-16T02:58:05.067 回答