'declaration' : 無法推斷 'identifier' 的範本自變數
備註
編譯程式無法判斷範本自變數。 默認自變數無法用來推斷範本自變數。
範例
下列範例會產生 C2783:
// C2783.cpp
template<typename T1, typename T2>
T1 f(T2) {
return 248;
}
int main() {
f(1); // C2783
// try the following line instead
int i = f<int>(1);
}
使用泛型時,也會發生 C2783:
// C2783b.cpp
// compile with: /clr
using namespace System;
generic<typename T1, typename T2>
T1 gf(T2) {
T1 t1 = safe_cast<T1>( Activator::CreateInstance(T1::typeid));
return t1;
}
ref class MyClass{};
int main() {
int i;
i = gf(9); // C2783
// OK
i = gf<int>(9);
}