C++11 anonymous union with non-trivial members
问题 I\'m updating a struct of mine and I was wanting to add a std::string member to it. The original struct looks like this: struct Value { uint64_t lastUpdated; union { uint64_t ui; int64_t i; float f; bool b; }; }; Just adding a std::string member to the union, of course, causes a compile error, because one would normally need to add the non-trivial constructors of the object. In the case of std::string (text from informit.com) Since std::string defines all of the six special member functions,