using a union-like class in an std::initializer_list
问题 In the code below I show union-like class S which contains two non-related structs B and C. I show how to instantiate the non-POD std::string and delete it again and then switch S to S::CC and set the num int. #include <vector> #include <string> #include <iostream> #include <memory> struct B { B() {} ~B() {} std::string str; void Func1() {} }; struct C { C() {} ~C() {} int num; void Func2() {} }; struct S { S() { tag = CC; } S( const S& s ) { switch( s.tag ) { case BB: new ( &b.str ) std: