P
Pavel
In 9.4.2, paragraph 5, the standard says:
If a static data member is of const integral or const enumeration type,
its declaration in the class definition can specify a
constant-initializer which shall be an integral constant expression
(5.19). In that case, the member can appear in integral constant
expressions. *The member shall still be defined in a namespace scope if
it is used in the program and the namespace scope definition shall not
contain an initializer*.
The following program does not define the member MY_INT_MAX_0 as (in my
reading) is required in the above paragraph, but uses it nevertheless:
--------cut here--------
#include <iostream>
using namespace std;
struct S0 {
static const int MY_INT_MAX_0 = 2147483647;
};
int main() {
cout << S0::MY_INT_MAX_0 << endl;
return 0;
}
------cut here-----------
However, it compiles and runs without problem in gcc (I tried 3.4.4 and
4.3.1) and MSVC++ (14.00). Are all 3 compilers over-permissive or is my
understanding of the standard wrong: that the program shall have a
definition like
int S0::MY_INT_MAX_0;
at the global scope?
-Pavel
If a static data member is of const integral or const enumeration type,
its declaration in the class definition can specify a
constant-initializer which shall be an integral constant expression
(5.19). In that case, the member can appear in integral constant
expressions. *The member shall still be defined in a namespace scope if
it is used in the program and the namespace scope definition shall not
contain an initializer*.
The following program does not define the member MY_INT_MAX_0 as (in my
reading) is required in the above paragraph, but uses it nevertheless:
--------cut here--------
#include <iostream>
using namespace std;
struct S0 {
static const int MY_INT_MAX_0 = 2147483647;
};
int main() {
cout << S0::MY_INT_MAX_0 << endl;
return 0;
}
------cut here-----------
However, it compiles and runs without problem in gcc (I tried 3.4.4 and
4.3.1) and MSVC++ (14.00). Are all 3 compilers over-permissive or is my
understanding of the standard wrong: that the program shall have a
definition like
int S0::MY_INT_MAX_0;
at the global scope?
-Pavel