C语言中 错误initializer list being treasted as compound expression什么意思?
答案:2 悬赏:10
解决时间 2021-01-27 23:50
- 提问者网友:你给我的爱
- 2021-01-27 15:22
C语言中 错误initializer list being treasted as compound expression什么意思?
最佳答案
- 二级知识专家网友:独钓一江月
- 2021-01-27 16:32
initializer list being treasted as compound expression意思为:初始化列表被看作为复合表达式(如逗号表达式)
这是g++编译器报的错误,常见错误情况一般是在函数调用时,函数名前加了返回值类型,且,函数参数还有多个时,如:
//错误代码
#include
void func(char *s,char *str)
{
}
int main()
{
char * s1=NULL, *str1="asfdgh";
void func(s1,str1); //只是这里写错了!!! 正确代码,应该去掉void!
return 0;
}g++编译时,报错如下:
test.cpp: In function 'int main()':
test..cpp:8: error: variable or field 'func' declared void 函数名func被看作变量了
test..cpp:8: error: initializer expression list treated as compound expression
test..cpp:8: warning: left-hand operand of comma has no effect
test..cpp:8: error: invalid conversion from 'char*' to 'int'
test..cpp:8: warning: unused variable 'func'
而用gcc编译时,会报警告:
test.c: In function 'main':
test.c:8: warning: parameter names (without types) in function declaration 函数声明中没有给定参数类型!
总结:
函数声明,函数调用是两个不同的格式,函数声明时,必须要指定参数类型和返回值类型,函数调用时,只需要输入相应的实参变量就可以了,不需要提供参数类型和返回值类型。
这是g++编译器报的错误,常见错误情况一般是在函数调用时,函数名前加了返回值类型,且,函数参数还有多个时,如:
//错误代码
#include
void func(char *s,char *str)
{
}
int main()
{
char * s1=NULL, *str1="asfdgh";
void func(s1,str1); //只是这里写错了!!! 正确代码,应该去掉void!
return 0;
}g++编译时,报错如下:
test.cpp: In function 'int main()':
test..cpp:8: error: variable or field 'func' declared void 函数名func被看作变量了
test..cpp:8: error: initializer expression list treated as compound expression
test..cpp:8: warning: left-hand operand of comma has no effect
test..cpp:8: error: invalid conversion from 'char*' to 'int'
test..cpp:8: warning: unused variable 'func'
而用gcc编译时,会报警告:
test.c: In function 'main':
test.c:8: warning: parameter names (without types) in function declaration 函数声明中没有给定参数类型!
总结:
函数声明,函数调用是两个不同的格式,函数声明时,必须要指定参数类型和返回值类型,函数调用时,只需要输入相应的实参变量就可以了,不需要提供参数类型和返回值类型。
全部回答
- 1楼网友:不想翻身的咸鱼
- 2021-01-27 18:00
初始化的时候发生重复错误
仔细看看
仔细看看
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯