现在的位置: 首页 > 综合 > 正文

解决VC错误error C2552:不聚合带用户定义的构造函数的类型

2017年10月05日 ⁄ 综合 ⁄ 共 269字 ⁄ 字号 评论关闭

当编译以下代码时,将收到错误

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

抱歉!评论已关闭.