const int problem...
Martin von Loewis
martin@mira.isdn.cs.tu-berlin.de
Mon Apr 6 17:35:00 GMT 1998
> 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 :-)
More information about the Gcc
mailing list