我最近开始搞乱虚空并遇到问题
这是我的代码:
#include <iostream>
using namespace std;
void smallSort();
int main()
{
int num1, num2, num3;
cout << "Please enter the first number" << endl;
cin >> num1;
cout << "Please enter the second number" << endl;
cin >> num2;
cout << "Please enter the third number" << endl;
cin >> num3;
cout << "Now I will sort from smallest to biggest!" << endl;
smallSort();
return 0;
}
void smallSort(int& num1, int& num2, int& num3){
if(num1 > num2)
swap(num1, num2);
if(num1 > num3)
swap(num1, num3);
if(num2 > num3)
swap(num2, num3);
cout << num1 << " " << num2 << " " << num3 << endl;
}
我试图在main中的smallSort中添加参数,但是它说参数太多了。我也试过从虚空中删除参数,但这也没有用。我能读到的任何提示或任何内容都会很棒,谢谢
答案 0 :(得分:4)
您的函数定义与其声明不匹配:
void smallSort(); // <== zero args
void smallSort(int& num1, int& num2, int& num3){ // <== three args
那些必须精确匹配。您的声明应更改为:
void smallSort(int&, int&, int&);
此外,您实际上并未使用任何参数调用 smallSort
:
smallSort();
应该是:
smallSort(num1, num2, num3);