Compiler Error C2783
'declaration' : could not deduce template argument for 'identifier'
The compiler cannot determine a template argument. Default arguments cannot be used to deduce a template argument.
The following sample generates 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 can also occur when using generics:
// 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);
}