【发布时间】:2018-11-26 12:37:31
【问题描述】:
我希望能够在 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 方法,因为那样我将需要通过我不想使用的双点或三点来调用参数,因为所有成员都同等重要,而且看起来不好读。
【问题讨论】:
-
那么错误信息是什么?您可以使用哪种 C++ 标准?
-
完全有效的 C++17,没有什么可重现的。
标签: c++ initialization c++14