This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: const int problem...


> class Curious {
> static const int c2 = 11;    // Correct, according to Bjarne
> const int c3 = 11;             // Incorrect, according to Bjarne, but
> correct according to standard
> };

No, incorrect according to the standard. [class.mem] says about member
syntax:

 member­declarator:
   declarator pure­specifier-opt 
   declarator constant­initializer-opt 
   identifier-opt : constant­expression

 constant­initializer: 
   = constant­expression

Paragraph 4 then says

  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.

»c3« in the example contains a constant-initializer, but it does
not declare a static member (unlike c2), so this is an incorrect
declaration.

Martin

P.S. It took me a while to remember what the last form of
member-declarator declares :-)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]