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?
The union itself must have an explicit ctor -- thanks to this article ):
union _u{
A a;
_u(){};
} a;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.