Statically initialize anonymous union in C++
- by wpfwannabe
I am trying to statically initialize the following structure in Visual Studio 2010:
struct Data
{
int x;
union
{
char ch;
const Data* data;
};
};
The following is fails with error C2440: 'initializing' : cannot convert from 'Data *' to 'char'.
static Data d1;
static Data d = {1, &d1};
I have found references to some ways this can be initialized properly but none of them work in VS2010. Any ideas?