#define N 10;
int main()
{
int x;
for (int i=0; i<N; i++)
x = i;
return 0;
}
在 g++ 中编译的结果:
test-define.cpp: In function ‘int main()’:
test-define.cpp:7:22: error: expected primary-expression before ‘;’ token
test-define.cpp:7:22: error: expected ‘)’ before ‘;’ token
test-define.cpp:7:24: error: name lookup of ‘i’ changed for ISO ‘for’ scoping [-fpermissive]
test-define.cpp:7:24: note: (if you use ‘-fpermissive’ G++ will accept your code)
test-define.cpp:7:27: error: expected ‘;’ before ‘)’ token
但是当我将第 7 行更改为for (int i=0; i<10; i++)
.
为什么会这样,我如何使用该#define
指令来完成我想要的?