错误:控件到达非void函数的末尾
Error: control reaches end of non-void function?
这是我的任务:"编写一个函数,在主程序中找到输入的两个整数中较大的一个,但允许您使用pass-by-reference更改函数中整数的值。"!!这项作业今晚到期了!!这是我目前的代码:
#include <iostream>
using namespace std;
int change(int& x, int& y)
{
int temp=0;
cout << "Function(before change): " << x << " " << y << endl;
temp = x;
x = y;
y = temp;
cout << "Function(after change): " << x << " " << y << endl;
}
int main()
{
int x,y;
cout << " Please Enter your first number: ";
cin >> x;
cout << " Please Enter your second number: ";
cin >> y;
if (x > y)
cout << x << " is greater than " << y << endl;
if (x < y)
cout << y << " is greater than " << x << endl;
if (x == y)
cout << x << " is equal to " <<y << endl;
cout << "Main (before change): " << x << " " << y << endl;
change(x, y);
cout << "Main (after change): " << x << " " << y << endl;
system("Pause");
return 0;
}
change
被声明为返回int
,但它从不返回任何内容。看起来您的函数不应该返回任何内容,所以只需将其声明为void
:
void change(int& x, int& y)
相关文章:
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- 在c++类上调用void函数
- 在派生函数中指定void*参数
- C++为什么尽管我调用了void函数,它却不起作用
- 如何从void函数输出字符串
- 为什么这个函数将"const char*"转换为"void* const"而不是"const void*"
- 将尾部调用void(i32,..)位转换为llvm::函数以获取FnAttribute
- 库函数需要一个 std::function<void(void)>,如何传入类函数?
- 如何将指针从一个void函数传递到另一个C++
- 为什么全局函数 void showA(A&x) 能够访问 A 类的私有成员?
- 如何将函数<void()>写入管道/套接字对?
- 错误:无法在没有对象的情况下调用成员函数'void Fortest::run()'|
- 标准的大小::函数<void(int&)>类型
- 如何函数<void(字符串消息)>绑定到成员函数?
- 函数void()返回一个值,而不是char或string
- 函数void QQuickWindow::setDefaultAlphaBuffer(bool useAlpha)的用途
- 错误 LNK2019:函数 "void __cdecl Padding(int)" 中引用未解析的外部符号___iob_func
- 我可以有一个~析构函数(void)吗?
- 函数<void(T)> 带有默认参数的参数
- 错误:参数太少,无法函数"void alpha(std::string*,student)"