D
Drew McCormack
I have a C++ template class which contains a static variable whose
construction registers the class with a map. Something like this:
template <typename T>
class M {
static Registrar<M> registrar;
};
The constructor of Registrar does the registering when it is initialized.
My problem is, I can't get this to work for a general class M<T>. I can
get it to work for a specific instance, like M<double>, by including the
initialization definition in the .cpp file:
Registrar< M<double> > M<double>::registrar;
but the general case doesn't work:
template <typename T>
Registrar< M<T> > M<T>::registrar;
It doesn't matter where I put this code --- in the header or .cpp file
--- the Registrar constructor does not get called.
Can anyone tell me where I should put the definition, and whether I need
to do something special with gcc (v3.3) options?
Drew
construction registers the class with a map. Something like this:
template <typename T>
class M {
static Registrar<M> registrar;
};
The constructor of Registrar does the registering when it is initialized.
My problem is, I can't get this to work for a general class M<T>. I can
get it to work for a specific instance, like M<double>, by including the
initialization definition in the .cpp file:
Registrar< M<double> > M<double>::registrar;
but the general case doesn't work:
template <typename T>
Registrar< M<T> > M<T>::registrar;
It doesn't matter where I put this code --- in the header or .cpp file
--- the Registrar constructor does not get called.
Can anyone tell me where I should put the definition, and whether I need
to do something special with gcc (v3.3) options?
Drew