如何编译此代码?
struct A
{
A() : b{}, c{} {}
~A() {}
union tag
{
const std::shared_ptr<int> b;
const std::shared_ptr<int> c;
} m_dfs;
};
int main()
{
A a;
}
我从VS2017编译器收到以下错误:
warning C4624: 'A::tag': destructor was implicitly defined as deleted
error C2614: 'A': illegal member initialization: 'b' is not a base or member
error C2614: 'A': illegal member initialization: 'c' is not a base or member
我认为我在gcc 7中有类似的问题。
根据评论进行更新。这个编译
struct A
{
A() : m_dfs{} {}
~A() {}
union tag
{
const std::shared_ptr<int> b;
const std::shared_ptr<int> c;
~tag() {};
} m_dfs;
};
int main()
{
A a;
}