<分区>
我希望能够在 C++14 中使用以下语法初始化一个对象:
const auto data1 = DataOne{1, 2, 3};
const auto data2 = DataTwo{1, 2, 3, 4, 5};
const auto data3 = DataThree{1, 2, 3, 4, 5, 6, 7};
这给了我以下错误信息:
error msg `error: no matching function for call to ‘DataThree::DataThree(<brace-enclosed initializer list>)’`
类型定义为:
struct DataOne
{
int a;
int b;
int c;
};
struct DataTwo : DataOne
{
int d;
int e;
};
struct DataThree : DataTwo
{
int f;
int g;
};
我不想使用 struct in struct 方法,因为那样我将需要通过双点或三点调用参数,我不想使用它,因为所有成员都同等重要,它看起来不好读。