错误C2614:非法成员初始化:'b'不是基础或成员

时间:2017-12-21 08:43:34

标签: visual-studio-2017 c++14

如何编译此代码?

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;
}

0 个答案:

没有答案