Topic: initializing const member data
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Tue, 24 May 1994 22:03:05 GMT Raw View
In article <CqA56H.3rG@pau.synnet.com> eric@synnet.com (Eric Baur) writes:
>According to both the ARM and (at least one version of) the draft ANSI
>standard the following is NOT legal:
There is no draft, and its a joint ANSI/ISO effort.
>
> class X {
> const int xdata = 100;
> };
>
>Yet rumors persist that at the last meeting of the X3J16 committee
>this syntax for initialization of const members was "approved".
Both X3J16 and WG21 approved this extension, yes. But it is:
class X {
static const int xdata = 100;
};
>Is this, in fact, the case?
Yes, its the case.
>If so, were any additional semantics
>specified, e.g. are such members implicitly static?
You have to specify 'static' I believe. Anything else
would be confusing. Non-static member may not be initialised in-class
(unfortunately)
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd, CSERVE:10236.1703
6 MacKay St ASHFIELD, Mem: SA IT/9/22,SC22/WG21
NSW 2131, AUSTRALIA
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Tue, 24 May 1994 22:08:40 GMT Raw View
In article <CqA7My.3ux@borland.com> pete@genghis.interbase.borland.com (Pete Becker) writes:
> What was passed is in-class initialization of static const data
>members. You must still provide a separate definition, and either the
>declaration or the definition can have an initializer, but not both.
Woops, I forgot to say that.
And we both forgot to say that it only works for
const _integral_ types initialised by constant expressions.
In other words, its much the same as using an enum,
except you have to provide a definition. I think I'll stick to enums.
Less typing :-)
--
JOHN (MAX) SKALLER, INTERNET:maxtal@suphys.physics.su.oz.au
Maxtal Pty Ltd, CSERVE:10236.1703
6 MacKay St ASHFIELD, Mem: SA IT/9/22,SC22/WG21
NSW 2131, AUSTRALIA
Author: eric@synnet.com (Eric Baur)
Date: Mon, 23 May 1994 23:56:40 GMT Raw View
According to both the ARM and (at least one version of) the draft ANSI
standard the following is NOT legal:
class X {
const int xdata = 100;
};
Yet rumors persist that at the last meeting of the X3J16 committee
this syntax for initialization of const members was "approved".
Is this, in fact, the case? If so, were any additional semantics
specified, e.g. are such members implicitly static?
Thanks,
Eric Baur eric@synnet.com
Synernetics Inc.
Author: pete@genghis.interbase.borland.com (Pete Becker)
Date: Tue, 24 May 1994 00:49:45 GMT Raw View
In article <CqA56H.3rG@pau.synnet.com>, Eric Baur <eric@synnet.com> wrote:
>According to both the ARM and (at least one version of) the draft ANSI
>standard the following is NOT legal:
>
> class X {
> const int xdata = 100;
> };
>
>Yet rumors persist that at the last meeting of the X3J16 committee
>this syntax for initialization of const members was "approved".
>Is this, in fact, the case? If so, were any additional semantics
>specified, e.g. are such members implicitly static?
>
That initialization is not legal, and won't be. After all, just because
it's const, that doesn't mean that every instance of X should have the same
value.
What was passed is in-class initialization of static const data
members. You must still provide a separate definition, and either the
declaration or the definition can have an initializer, but not both.
class X
{
static const int Value = 3;
};
const int X::Value;
or
class Y
{
static const int Value;
};
const int Y::Value = 3;
-- Pete
Author: jason@cygnus.com (Jason Merrill)
Date: Tue, 24 May 1994 01:17:18 GMT Raw View
>>>>> Eric Baur <eric@synnet.com> writes:
> According to both the ARM and (at least one version of) the draft ANSI
> standard the following is NOT legal:
> class X {
> const int xdata = 100;
> };
> Yet rumors persist that at the last meeting of the X3J16 committee
> this syntax for initialization of const members was "approved".
> Is this, in fact, the case? If so, were any additional semantics
> specified, e.g. are such members implicitly static?
Yes. Such members must be declared static AND defined in exactly one
place; they mimic other static data members, rather than file-scope static
consts.
foo.h:
class X {
static const int xdata = 100;
};
foo.C:
const int X::xdata;
Jason