Example of Static Data Members in Templates

In the following example:

template<class L> class Key
{
      static L k;
      static L* kptr;
      static int length;
      // ...
}

The definitions of static variables and objects must be instantiated at file scope. If the classes Key<int> and Key<double> are instantiated from this template, and no template definitions exist , the following static data members must be explicitly defined at file scope, or an error occurs:

int Key<int>::k, Key<int>::length, Key<double>::length;
int* Key<int>::kptr;
double Key<double>::k;
double* Key<double>::kptr = 0;