Unions in C++11: default constructor seems to be deleted

后端 未结 2 997
孤独总比滥情好
孤独总比滥情好 2021-02-14 02:00

I am trying to understand how unions were extended by C++11. One thing that changed is the ability to use now non-static data members with non-trivial special member functions.

2条回答
  •  感情败类
    2021-02-14 02:40

    The cppreference quote is unclear. What happens is that if ANY memeber of the union defines ANY of those non-trivial special member functions, then ALL of them will be deleted by default in the union.

    So since you have a non-trivial destructor for X, the U default constructor is deleted.

提交回复
热议问题