这是一个非常简单的程序。我在顶部定义了一个函数,在循环中我正在调用该函数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;
}