Re: Quick sanity check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux