Invalid union member
c++, c++11, unions, visual-studio, visual-studio-2013
Solution
I agree with @Shafik Yaghmour but there is an easy workaround. Just put your `foo` member into an `unnamed struct` like so:
union CustomUnion {
struct{
Foo foo;
};
int bar;
};
Problem
Is there a way in Visual Studio to handle non-trivial unions. The following code is running fine using `g++ -std=c++11` but VS complains: invalid union member -- class "Foo" has a disallowed member function The code is as follows: ``` struct Foo { int value; Foo(int inV = 0) : value(inV) {} }; union CustomUnion { CustomUnion(Foo inF) : foo(inF) {} CustomUnion(int inB) : bar(inB) {} int bar; Foo foo; }; int main() { CustomUnion u(3); return 0; } ``` Is there a way in Visual Studio to support this kind of unions (compilation option for instance)? Or should I change my code, and if so by what?