我定义了一个结构体,示意如下:
Struct A
{
int x;
CString test;
};
然后我定义一个变量同时对其进行串行初始化:
A a = {0, "hello"};
编译出现错误:non-aggregates cannot be initialized with initializer list
后来发现,可进行串行初始化的数据结构中是不能够有construct、private、protected等且没有基类的联合体、结构体、类。其成员也必须符合这样的条件。
编译出错是因为,A结构中成员“test”是CString类型,有构造函数。
以下结构可以进行initializer list,
class c1assDemo
{
public:
int x;
char c;
};
struct A
{
int x;
char test[256];
c1assDemo demo;
};