Kommentar
Åtkomst till den här sidan kräver auktorisering. Du kan prova att logga in eller ändra kataloger.
Åtkomst till den här sidan kräver auktorisering. Du kan prova att ändra kataloger.
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;
}
X created. In Test. 9