[英]Struct with `initializer_list` ctor inside union?
I have a struct which is POD, but for convenience, I want it to have std::initializer_list
ctor. 我有一个POD结构,但是为了方便起见,我希望它具有
std::initializer_list
ctor。 Default ctor, copy ctor and dtor are implicit. 默认ctor,copy ctor和dtor是隐式的。 It seems however that using
initializer_list
ctor disqualifies the struct as POD, hence it cannot be inside a union: 但是,似乎使用
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: 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?
它与c ++ 11的无限制联合功能有关吗?
The union itself must have an explicit ctor -- thanks to this article ): 工会本身必须有一个明确的ctor-感谢本文 ):
union _u{
A a;
_u(){};
} a;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.