首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

#define定义的常量不能作为函数的参数麻?该怎么解决

2012-03-23 
#define定义的常量不能作为函数的参数麻?如题:#include iostream.h#define maxsize 100int add(int t){

#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;

热点排行