www.digitalmars.com         C & C++   DMDScript  

c++.beta - Template static data member

reply Richard Grant <fractal clark.net> writes:
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
parent reply Richard Grant <fractal clark.net> writes:
Oops, wrong source file.. the code example I gave works just fine.

Richard
Feb 28 2003
parent Richard Grant <fractal clark.net> writes:
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