我的代码是:
std::vector<double> Vec;
template<typename T>
void GetObj(VARIANT &vtProp)
{
CComSafeArray<T> SafeArray;
SafeArray.Attach(vtProp.parray);
ULONG Count = SafeArray.GetCount();
Vec.resize(Count);
for(ULONG Index = 0; Index < Count; Index++)
{
Vec[Index] = SafeArray[Index];
}
}
编译时出现以下错误:
error C2783: 'void __cdecl GetObj(struct tagVARIANT &)' : could not deduce template argument for 'T'
请告诉我正确的答案
最佳答案
函数模板的签名中没有任何内容允许编译器推断模板类型,因此您需要明确:
GetObj<TheActualType>(arg);
关于c++ - 无法推断 'T' 的模板参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19221183/