G++ und anonymous struct, enum, union
-
Hi
Hab das Problem, daß der Code unter G++ nicht richtig Compiled. Wo liegt der Fehler:
template <typename TYPE> class Handle { private: union { enum { MAX_BITS_INDEX = 16, MAX_BITS_MAGIC = 16, MAX_INDEX = ( 1 << MAX_BITS_INDEX ) - 1, MAX_MAGIC = ( 1 << MAX_BITS_MAGIC ) - 1 }; struct { unsigned _index : MAX_BITS_INDEX; unsigned _magic : MAX_BITS_MAGIC; }; unsigned int _handle; }; ....
G++ Beschwert sich wegen dem Annonymous Union und Enum. Wie kann ich das abstellen?
template<typename TYPE> void Handle<TYPE> :: Init( unsigned int index ) { assert( IsNull() ); assert( index <= MAX_INDEX ); static unsigned int autoMagic = 0; if( ++autoMagic > MAX_MAGIC ) { autoMagic = 1; } _index = index; _magic = autoMagic; _data = NULL; }
Die Beschwerden fallen bei MAX_MAGIC und MAX_INDEX.
Unter M$VC Compiled der Code einwandfrei.Hier die kompletten Fehlermeldungen:
g++ -g -c -o main.o main.cpp
In file included from main.cpp:4:
Handle.h: In member functionvoid Handle<TYPE>::Init(unsigned int)': Handle.h:14:
Handle<TYPE>::<anonymous union>::<anonymous enum>
Handle<TYPE>::<anonymous union>::MAX_INDEX' is inaccessible
Handle.h:44: within this context
Handle.h:16:Handle<TYPE>::<anonymous union>::<anonymous enum> Handle<TYPE>::<anonymous union>::MAX_MAGIC' is inaccessible Handle.h:47: within this context In file included from main.cpp:5: Handle.h: At global scope: Handle.h: In instantiation of
Handle<int>':
Test.cpp:5: instantiated from here
Handle.h:10:Handle<int>::<anonymous union>::<anonymous enum> Handle<int>::<anonymous union>::MAX\_BITS\_INDEX' invalid; an anonymous union can only have non-static data members Handle.h:10:
Handle<int>::<anonymous union>::<anonymous enum>
Handle<int>::<anonymous union>::MAX_BITS_MAGIC' invalid; an anonymous union
can only have non-static data members
Handle.h:10:Handle<int>::<anonymous union>::<anonymous enum> Handle<int>::<anonymous union>::MAX_INDEX' invalid; an anonymous union can only have non-static data members Handle.h:10:
Handle<int>::<anonymous union>::<anonymous enum>
Handle<int>::<anonymous union>::MAX_MAGIC' invalid; an anonymous union can
only have non-static data membersDanke
Sven
-
Ach ja - wenn ich das enum weglasse, und die 4 Variablen vorher per
const unsigned int blabla
definiere Rockts auch unter g++