This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
const int problem...
- To: egcs at cygnus dot com
- Subject: const int problem...
- From: Mark Schaefer <mschaefer at dsai dot com>
- Date: Wed, 11 Mar 1998 18:38:49 -0700
- Organization: Decision-Science Applications, Inc.
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