错误:控制到达非无效功能的末尾.找不到修复错误的位置
Error: Control reaches end of non-void function. Cant find where to fix the error
我找不到错误,错误位于函数(计算查找计算)中。
这就是代码似乎有问题的地方。
开始
calculation findCalculations(float A[][5], int rows) {
{
double sum = 0;
for (int x = 0; x < rows; x++) {
cout << endl;
for (int y = 0; y < 5; y++) {
sum = sum + A[x][y];
}
}
cout << "Average graylevel: " << sum << endl;
double min = 0;
for (int x = 0; x < rows; x++) {
for (int y = 0; y < 5; y++) {
if (A[x][y] < min) {
min = A[x][y];
}
}
}
cout << "Min graylevel: " << min << endl;
int graylevel = 0;
for (int x = 0; x < rows; x++) {
for (int y = 0; y < 5; y++) {
if (A[x][y] >= .75) {
graylevel = A[x][y];
}
}
cout << "Number of bright pixels: " << graylevel << endl;
}
bool bright = true;
bool dark = false;
for (int x = 0; x < rows; x++) {
for (int y = 0; y < 5; y++) {
if (A[x][y] < .5) {
bright = A[x][y];
}
if (A[x][y] >= .5) {
dark = A[x][y];
}
}
if (dark < bright) {
cout << "Image has more bright pixels: yes" << endl;
} else if (dark == bright) {
cout << "Image has more bright pixels: they have the same" << endl;
} else {
cout << "Image has more bright pixels: no" << endl;
}
}
}
}
停
如果有人可以帮助我找出出了什么问题,那将意味着非常感谢。
你在函数签名中告诉编译器
calculation findCalculations(float A[][5], int rows)
该函数正在返回一个calculation
对象。但是你的函数中没有实际这样做的 return 语句。你只是通过cout
输出东西.如果您实际上不需要从函数返回任何内容,则应将函数签名更改为
void findCalculations(float A[][5], int rows)
向编译器指示这一点。如果调用此函数的代码实际上需要calculation
对象,则必须通过 return
语句在函数中的某个位置创建并返回它们。
相关文章:
- OpenGL 4.3 错误地将第 4 个纹理坐标映射到与第 3 个纹理坐标相同的位置
- 0xC0000005:访问冲突写入位置0xCDCDCDCD动态分配错误
- 奇怪的Arduino C++编译错误取决于文件位置
- 我收到分段错误,但不了解分段错误发生的位置
- 访问特定阵列位置/索引时出现分段错误
- boost::p rogram_options 在指定意外的位置参数时不报告任何错误
- 快速排序;分段错误,但找不到位置?
- 在尝试使用CUDA分配内存时,我遇到了访问冲突写入位置错误
- 错误 在测试.exe 0x76C9FD62时出现未经处理的异常:Microsoft C++异常:内存位置0x006FF8
- 错误:内存位置的 std::length_error
- 处于默认参数位置的 Lambda 无法访问好友成员。这是编译器错误吗?
- 无法指出发生分段错误的位置
- 在 C 代码中调用 Python 函数时第三次出现访问冲突写入位置错误
- 目标提升::<library>已经有导入的位置 + 链接错误
- 如何使用 Poco Json 解析器确定输入文档中错误的位置?
- 在动态加载的位置无关的可执行文件中分离错误
- Visual studio显示SEH异常的错误位置
- 编译器运行时错误报告和错误位置
- 核心转储,但是找不到错误位置,有GDB的错误信息
- 如何使用精灵解析器获得错误位置