c++.beta - Template static data member
- Richard Grant (10/10) Feb 28 2003 It is surprisingly difficult to work around this without an obj file.. a
- Richard Grant (2/2) Feb 28 2003 Oops, wrong source file.. the code example I gave works just fine.
- Richard Grant (18/19) Feb 28 2003 But this one does not. This is an example of a static data member initia...
It is surprisingly difficult to work around this without an obj file.. a function template friend get/set with static local might work. template <class T1> struct A { static int val; } template <class T1> int A<T1>::val = 0; int main() { } // Internal error: init 1864 Richard
Feb 28 2003
Oops, wrong source file.. the code example I gave works just fine. Richard
Feb 28 2003
In article <b3ntf5$2qhd$1 digitaldaemon.com>, Richard Grant says...Oops, wrong source file.. the code example I gave works just fine.But this one does not. This is an example of a static data member initialized via a conversion c'tor. struct B { B(const char* c) { } }; template <class T1> class A { static B val; }; template <class T1> B A<T1>::val = "test"; int main() { A<int> a; } // Internal error: init 1864 If the template class is changed to a non template class, the example compiles. This can be worked around by making the static a char* and performing the conversion to a temporary when needed. Richard
Feb 28 2003