Quick sanity check

Denis Nagorny denis_nagorny@linux.intel.com
Mon Feb 20 06:51:00 GMT 2006


You'd be guided by 9.2 p4:
"A member-declarator can contain a constant-initializer only if it declares a static member (9.4)
of integral or enumeration type, see 9.4.2."
As &sge::flags isn't integral type (It's pointer-to-member) you need take initializer out of class declaration.
class sge
{
public:
   uint64_t address;
   uint32_t count;
   uint32_t flags;
};

class bitfield
{
public:
   const uint32_t sge::*field;// = &sge::flags;
//                           ^^^^^^^^^^^^^^^^^
   static const uint32_t bit_start = 31;
   static const uint32_t bit_stop = 31;
};

const uint32_t sge::*field = &sge::flags;
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

> class sge {
> public:
>     uint64_t address;
>     uint32_t count;
>     uint32_t flags;
> };
> 
> class bitfield {
> public:
>     const uint32_t sge::*field = &sge::flags;
>     static const uint32_t bit_start = 31;
>     static const uint32_t bit_stop = 31;
> };
> 
> g++ -o foo foo.C && ./foo
> foo.C:14: error: 'sge::flags' cannot appear in a constant-expression
> foo.C:14: error: `&' cannot appear in a constant-expression
> foo.C:14: error: ISO C++ forbids initialization of member 'field'
> foo.C:14: error: making 'field' static
> foo.C:14: error: invalid in-class initialization of static data  member 
> of non-integral type 'const uint32_t sge::*'
> 
> Thank you,
> Perry
> 



More information about the Gcc-help mailing list