編譯器錯誤 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
}