【发布时间】:2012-07-03 13:34:43
【问题描述】:
这是一个非常简单的程序。我在顶部定义了一个函数,在循环中我调用了函数print。
但我收到以下错误:
prog.cpp:5: error: variable or field ‘print’ declared void
prog.cpp:5: error: ‘a’ was not declared in this scope
prog.cpp: In function ‘int main()’:
prog.cpp:11: error: ‘print’ was not declared in this scope
这里是:
#include <iostream>
using namespace std;
void print( a ) {
cout << a << endl;
}
int main() {
for ( int i = 1; i <= 50; i++) {
if ( i % 2 == 0 ) print( i );
}
return 0;
}
【问题讨论】:
-
函数参数中“a”的类型?
-
为什么有这么多反对票? OP 提供了一个最小的工作示例,并且错误消息是完整的。
-
@Gigi 我正在阅读它,它真的很棒。谢谢!