编译器错误 C2252

无法在当前范围内显式实例化模板

编译器检测到模板的显式实例化出现问题。 例如,不能在函数中显式实例化模板。

以下示例生成 C2252:

// C2252.cpp
class A {
public:
   template <class T>
   int getit(int i , T * it ) {
      return i;
   }
   template int A::getit<double>(int i, double * it);   // C2252
   // try the following line instead
   // template <> int A::getit<double>(int i, double * it);

};

int main() {
   // cannot explicitly instantiate in function
   template int A::getit<long>(int i, long * it);   // C2252
}