c++中initializer list being treasurized as compound expression是什么意思?

如题所述

initializer list being treasted as compound expression意思为:初始化列表被看作为复合表达式(如逗号表达式)

这是g++编译器报的错误,常见错误情况一般是在函数调用时,函数名前加了返回值类型,且,函数参数还有多个时,如:

//错误代码
#include<stdio.h>
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 函数声明中没有给定参数类型!

总结:

函数声明,函数调用是两个不同的格式,函数声明时,必须要指定参数类型和返回值类型,函数调用时,只需要输入相应的实参变量就可以了,不需要提供参数类型和返回值类型。

温馨提示:答案为网友推荐,仅供参考
相似回答
大家正在搜