Templates for Class MembersĀ
When creating an out-of-line definition for a member of a template class, the template parameters should be specified on the type name and not on the member name.
Example
// templates_for_class_members.cpp
// compile with: /EHsc
#include <iostream>
using namespace std;
template <class T>
struct X {
X();
void Test();
static const int i;
};
template <class T>
X< T >::X() {
cout << "X created." << endl;
}
template <class T>
void X< T >::Test() {
cout << "In Test." << endl;
}
template <class T>
const int X<T>::i = 9;
int main() {
X<int> x;
x.Test();
cout << X<int>::i << endl;
}
Output
X created. In Test. 9