Thread overview | |||||
---|---|---|---|---|---|
|
February 28, 2003 Template static data member | ||||
---|---|---|---|---|
| ||||
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 |
February 28, 2003 Re: Template static data member | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard Grant | Oops, wrong source file.. the code example I gave works just fine. Richard |
February 28, 2003 Re: Template static data member | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard Grant | 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 |
Copyright © 1999-2021 by the D Language Foundation