This is the mail archive of the 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]

const int problem...

    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.  (

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;

  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

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