A
ALiX
Hi!
My template class has a const static data member, which is used by the
constructor. It seems that the program does not produce the correct
result. Either it is the fault of the compiler (gcc 4.1) or I need to
learn more about initialization of static members... The code below
captures the problem and is as simple as I could make it:
#include <iostream>
#include <limits>
template<typename T> struct A {
const static unsigned NONE;
unsigned x;
A() { x = NONE; }
};
template<typename T> const unsigned A<T>::NONE =
numeric_limits<unsigned>::max();
A<double> a;
int main(void) {
cout << a.x << "\n";
cout << A<double>::NONE << "\n";
return 0;
}
The output of the program is:
0
4294967295
Mustn't NONE be initialized before a is constructed?
Cheers,
/ALiX
My template class has a const static data member, which is used by the
constructor. It seems that the program does not produce the correct
result. Either it is the fault of the compiler (gcc 4.1) or I need to
learn more about initialization of static members... The code below
captures the problem and is as simple as I could make it:
#include <iostream>
#include <limits>
template<typename T> struct A {
const static unsigned NONE;
unsigned x;
A() { x = NONE; }
};
template<typename T> const unsigned A<T>::NONE =
numeric_limits<unsigned>::max();
A<double> a;
int main(void) {
cout << a.x << "\n";
cout << A<double>::NONE << "\n";
return 0;
}
The output of the program is:
0
4294967295
Mustn't NONE be initialized before a is constructed?
Cheers,
/ALiX