c++ - Constructor and anonymous union with const members -
is possible have anonymous union const members? have following:
struct bar { union { struct { const int x, y; }; const int xy[2]; }; bar() : x(1), y(2) {} };
with g++ 4.5 error:
error: uninitialized member ‘bar::<anonymous union>::xy’ ‘const’ type ‘const int [2]’
this problem in gcc fixed in version 4.6. code works fine.
it still depends on gcc extension because uses anonymous struct, compilers support them now. also, following code builds -pedantic
:
struct bar { union { const int x; const int y; }; bar() : x(1) {} };
that code accepted clang , visual studio 2010 (but fails 2008).
Comments
Post a Comment