第一次与 Void 合作
working with void for the first time
我最近开始弄乱 void 并遇到了一个问题
这是我的代码:
#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;
}
我试图将参数添加到主节点中的 smallSort 中,但它说参数太多了。 我也尝试从空白中删除参数,但这也不起作用。 任何提示或任何我能阅读的东西都会很棒,谢谢
您的函数定义与其声明不匹配:
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);
相关文章:
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- 在c++类上调用void函数
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- 在派生函数中指定void*参数
- C++为什么尽管我调用了void函数,它却不起作用
- 如何从void函数输出字符串
- 我应该使用什么来代替void作为变体中的替代类型之一
- 奇怪的结构&GCC&clang(void*返回类型)
- Arduino:for/while/if在void setup()或void loop()之前?——错误:之前需要不合格
- 为什么这个函数将"const char*"转换为"void* const"而不是"const void*"
- 引用一个已擦除类型(void*)的指针
- 将尾部调用void(i32,..)位转换为llvm::函数以获取FnAttribute
- 库函数需要一个 std::function<void(void)>,如何传入类函数?
- 如何将指针从一个void函数传递到另一个C++
- 为什么我在使用void函数时得到错误代码C2276
- void*到驱动程序中的UnicodeString
- 为什么在逗号分隔符上下文中将预增量的结果强制转换为void
- 指针没有更新它在void函数内部指向的值
- 海湾合作委员会的"void pointer arithmetic"确定性吗?
- 第一次与 Void 合作