C++ boost绑定模板错误 //错误C2784:'HRESULT get_wrapper(T*,boost::function)': //无法推断“boost::function”的模板参数 //来自“boost::\u bi::bind\u t” STDMETHODIMP CAttributeValue::get_Name(BSTR*pVal) { 返回get_包装器(pVal,boost::bind(&CAttributeValue::getNameCOM,this));//此处出错 } 模板HRESULT get_包装(T*pVal,boost::function GetVal) { 如果(!pVal) 返回E_指针; HRESULT状态=E_失败; 试一试{ *pVal=GetVal(); 状态=S_正常; }捕获(…){} 返回状态; } BSTR CAttributeValue::getNameCOM()常量 { BOOST_STATIC_ASSERT(sizeof(TCHAR)=sizeof(wchar_t)); 返回tstr2combstr(_name).Detach(); }

C++ boost绑定模板错误 //错误C2784:'HRESULT get_wrapper(T*,boost::function)': //无法推断“boost::function”的模板参数 //来自“boost::\u bi::bind\u t” STDMETHODIMP CAttributeValue::get_Name(BSTR*pVal) { 返回get_包装器(pVal,boost::bind(&CAttributeValue::getNameCOM,this));//此处出错 } 模板HRESULT get_包装(T*pVal,boost::function GetVal) { 如果(!pVal) 返回E_指针; HRESULT状态=E_失败; 试一试{ *pVal=GetVal(); 状态=S_正常; }捕获(…){} 返回状态; } BSTR CAttributeValue::getNameCOM()常量 { BOOST_STATIC_ASSERT(sizeof(TCHAR)=sizeof(wchar_t)); 返回tstr2combstr(_name).Detach(); },c++,boost,boost-bind,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

这样做有帮助吗

//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();
}
返回get_包装(pVal,boost::bind(&CAttributeValue::getNameCOM,this));
//                ^^^^^^

>从代码>升迁::Boo< <代码> >代码> Boo::/>代码>,但是由于这个参数依赖于模板参数,编译器不会为您做任何此类转换。

[IHATE-C++ ]:不太坏,至少它不是java。我看到您在我的建议中编辑过,但我错了,对不起,不管怎样,它不痛,所以我把它留下
return get_wrapper<BSTR>(pVal, boost::bind(&CAttributeValue::getNameCOM, this));
//                ^^^^^^