提升绑定模板错误

时间:2010-08-12 19:29:30

标签: c++ boost boost-bind

//error C2784: 'HRESULT get_wrapper(T *,boost::function<R(void)>)' : 
//could not deduce template argument for 'boost::function<R(void)>' 
//from 'boost::_bi::bind_t<R,F,L>'

STDMETHODIMP CAttributeValue::get_Name(BSTR* pVal)
{
    return get_wrapper(pVal, boost::bind<BSTR>(&CAttributeValue::getNameCOM, this)); //error here
}

template <class T> HRESULT get_wrapper(T* pVal, boost::function<T()> GetVal)
{
    if(!pVal)
        return E_POINTER;
    HRESULT status = E_FAIL;
    try {
        *pVal = GetVal();
        status = S_OK;
    } catch (...) {}
    return status;
}

BSTR CAttributeValue::getNameCOM() const
{
    BOOST_STATIC_ASSERT(sizeof(TCHAR)==sizeof(wchar_t));
    return TStr2CComBSTR(_name).Detach();
}

1 个答案:

答案 0 :(得分:2)

这样做有帮助吗?

return get_wrapper<BSTR>(pVal, boost::bind(&CAttributeValue::getNameCOM, this));
//                ^^^^^^

boost::bind返回的类型转换为boost::function<T()>,但由于此参数取决于模板参数,因此编译器不会代表您进行任何此类转换。