#define定义的常量不能作为函数的参数麻?
如题:
#include <iostream.h>
#define maxsize 100;
int add(int t)
{
t+=10;
return t;
}
void main()
{
add(maxsize);
}
编译会报错,
F:\编程实践\test\test27.cpp(72) : error C2143: syntax error : missing ')' before ';'
F:\编程实践\test\test27.cpp(72) : error C2059: syntax error : ')'
Error executing cl.exe.
test27.obj - 2 error(s), 0 warning(s)
[解决办法]
#define maxsize 100; 宏定义时多写了分号
add(maxsize); 宏展开时了分号也加进到去了.变成add(100;);,
[解决办法]
宏只被完全替换,作为参数自然是可以的,前提没有语法错误。
[解决办法]
#define maxsize 100; 多了个分号
[解决办法]
#define maxsize 100
或者
const int maxsize = 100;