编译器错误 C3852
“member”具有类型“type”: 聚合初始化无法初始化该成员
在聚合初始化过程中,尝试将默认初始化分配到无法在聚合初始化中接收默认初始化的数据成员。
以下示例生成 C3852:
// C3852.cpp
struct S
{
short s;
};
struct S1
{
int i;
const S s;
};
struct S2
{
int i;
char & rc;
};
int main()
{
S1 s1 = { 1 }; // C3852 const member
// try the following line instead
// S1 s1 = { 1, 2 };
S2 s2 = { 2 }; // C3852 reference member
// try the following line instead
// char c = 'a';
S2 s2 = { 2, c };
}