当编译以下代码时,将收到错误
struct stype {
int a;
int b;
int c;
stype (){
a=0;
b=0;
c=0;
}
};
/* a, b, c */
struct stype rgstype[2] = { {8, 9, 10},
{15, 16, 17} };
d:\test.cpp(49) : error C2552: “rgstype”: 不能用初始值设定项列表初始化非聚合
“stype”: 不聚合带用户定义的构造函数的类型
解决方法:把构造函数去掉就可以了。
struct stype {
int a;
int b;
int c;
// stype (){a=0;b=0;c=0;}
};