* const int problem...
@ 1998-03-11 17:54 Mark Schaefer
1998-04-06 17:35 ` Martin von Loewis
0 siblings, 1 reply; 2+ messages in thread
From: Mark Schaefer @ 1998-03-11 17:54 UTC (permalink / raw)
To: egcs
Egcs developers,
Sorry to keep pointing out little annoyances. (To your credit, the
last one was 100% my stupidity)
According to a co-worker who's studied the proposed standard (I don't
have a copy to reference), Bjarne's third edition is incorrect about how
"const int x = 0" is treated as a class member. (10.4.6.2)
In a class,
class Curious {
static const int c2 = 11; // Correct, according to Bjarne
const int c3 = 11; // Incorrect, according to Bjarne, but
correct according to standard
};
In Bjarne's book this is considered an error, and it seems that egcs
considers it an error as well, i.e. the following code is better:
class Curious {
const int c3;
public:
Curious() : c3 (5) {}
};
According to the standard, example 1 is better and should 1) take no
space in the actual object, and 2) be implemented like other const's
(direct substitution)
All this info is second-hand so I'd be very curious as to what the
standard actually says. My co-worker seemed very convinced, however.
If he's right then code I got this error on is actually correct and
shouldn't be an error:
TgTrackLogId.H:49: warning: ANSI C++ forbids initialization of const
member `undefinedTrackLogId'
TgTrackLogId.H:49: warning: making `undefinedTrackLogId' static
--
Mark Schaefer
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: const int problem...
1998-03-11 17:54 const int problem Mark Schaefer
@ 1998-04-06 17:35 ` Martin von Loewis
0 siblings, 0 replies; 2+ messages in thread
From: Martin von Loewis @ 1998-04-06 17:35 UTC (permalink / raw)
To: mschaefer; +Cc: egcs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 898 bytes --]
> 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 :-)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1998-04-06 17:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-03-11 17:54 const int problem Mark Schaefer
1998-04-06 17:35 ` Martin von Loewis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).