Topic: const int?
Author: maxtal@physics.su.OZ.AU (John Max Skaller)
Date: Sun, 20 Feb 1994 23:22:33 GMT Raw View
In article writes:
>r!cornell!moudgill
>From: moudgill@cs.cornell.edu ( Mayan Moudgill)
>Subject: Static Const Members...
>Message-ID: <1994Feb7.141945.9324@cs.cornell.edu>
>Organization: Cornell Univ. CS Dept, Ithaca NY 14853
>Date: Mon, 7 Feb 1994 14:19:45 GMT
>Lines: 25
>
>Consider the following construct:
>
> class A {
> public:
> static const int x;
> };
>
> const int A::x = 30;
>
>Now, is A::x a const int, or a static int that happens to be unchangeable?
>The reason I'm asking is that I can use it like a const int. Thus I
>can use it to do something like the following, in global scope (using
>cfront 3.0.2):
>
> int foo[A::x];
>
>However, if I try to define it twice (by say declaring it in a .H file, and
>including the .H file twice), cfront 3.0.2 gives a multiply-definded error.
>
>So, what is the correct behavior? I'm confused, and I couldn't find anything
>in the ARM to indicate which view is correct.
You're confusing 'const int' with "constant expression".
But in this case, the ARM is confused too: the rules for
constant expressions are inadequate. The intent is clearly that
a const integral type initialised by a constant expression is a constant
expression ***provided the initialiser is visible***. That last
bit should have been said but wasnt.
--
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