This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: const int problem...
- To: mschaefer at dsai dot com
- Subject: Re: const int problem...
- From: Martin von Loewis <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Mon, 6 Apr 1998 22:52:23 +0200
- CC: egcs at cygnus dot com
- References: <98Mar11.183814mst.26883@colorado.dsai.com>
> 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:
memberdeclarator:
declarator purespecifier-opt
declarator constantinitializer-opt
identifier-opt : constantexpression
constantinitializer:
= constantexpression
Paragraph 4 then says
A memberdeclarator can contain a constantinitializer 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 :-)