在联合内部使用 `initializer_list` 构造函数?
我有一个 POD 结构,但为了方便起见,我希望它有 std::initializer_list
构造函数。默认构造函数、复制构造函数和 dtor 是隐式的。然而,使用 initializer_list
ctor 似乎会取消该结构作为 POD 的资格,因此它不能位于联合内:
#include<initializer_list>
struct A{
A(const std::initializer_list<int>&);
};
union{
A a;
} a;
gcc 4.6 --std=c++0x:
error: use of deleted function ‘<anonymous union>::._0()’
error: ‘<anonymous union>::._0()’ is implicitly deleted because the default definition would be ill-formed:
error: no matching function for call to ‘A::A()’
周围有吗?与c++11的无限制联合特性有关吗?
I have a struct which is POD, but for convenience, I want it to have std::initializer_list
ctor. Default ctor, copy ctor and dtor are implicit. It seems however that using initializer_list
ctor disqualifies the struct as POD, hence it cannot be inside a union:
#include<initializer_list>
struct A{
A(const std::initializer_list<int>&);
};
union{
A a;
} a;
gcc 4.6 --std=c++0x:
error: use of deleted function ‘<anonymous union>::._0()’
error: ‘<anonymous union>::._0()’ is implicitly deleted because the default definition would be ill-formed:
error: no matching function for call to ‘A::A()’
Is there away around it? Is it related to the unrestricted unions feature of c++11?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
联盟本身必须有一个明确的角色——感谢这篇文章< /a>):
The union itself must have an explicit ctor -- thanks to this article):