无法在 C++ 中从“void”转换为“int” - 有人知道为什么吗?有我必须使用的功能吗?
int calc_tot,go2;
go2=calculate_total(exam1,exam2,exam3);
calc_tot=read_file_in_array(exam);
最佳答案
go2=calculate_total(exam1,exam2,exam3);
calc_tot=read_file_in_array(exam);
我的猜测是这两个函数之一返回 void,因此您不能将该值分配给 int。由于“void”函数不返回任何内容,因此您不能将其返回值分配给 int。
我希望这样的代码会给你这样的错误:
void voidfunc () {
// Do some things
}
int main () {
int retval = voidfunc();
return 0;
}
虽然我的编译器给出:
$ g++ main.c
main.c: In function ‘int main()’:
main.c:6: error: void value not ignored as it ought to be
关于c++ - 无法从 "void"转换为 "int",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2747420/