简体   繁体   English

无法推断出“ T”的模板参数

[英]could not deduce template argument for 'T'

My code is : 我的代码是:

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];
    }
}

while compilation I got the error below: 编译时出现以下错误:

error C2783: 'void __cdecl GetObj(struct tagVARIANT &)' : could not deduce template argument for 'T'

Kindly suggest me the correct answer 请给我正确的答案

函数模板的签名中没有任何内容允许编译器推断模板类型,因此您需要明确:

GetObj<TheActualType>(arg);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM