c++ - 无法推断 'T' 的模板参数

标签 c++ templates visual-c++

我的代码是:

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/

相关文章:

c++ - LLVM 下的非 ASCII wchar_t 文字

c++ - 拆分给定类型的参数包

c - 使用 CMake 设置平台特定/编译器特定的目标属性

c++ - 在 cpp 文件中定义模板函数 - 不适用于 VC6

c++ - 一次只能操纵一个 union 成员是什么意思?

c++ - C++ header 中外部变量的 undefined reference

c++ - 如何从 C 风格的 const char* 数组中提取整数

python - 如何创建 jinja2 扩展?

c++ - C++中调用基类模板构造函数

c++ - Gstreamer 动态更改源元素