Ошибка в шаблоне Bind 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 ответ

Решение

Помогает ли это сделать?

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

Существует преобразование из типа, возвращаемого boost::bind в boost::function<T()>, но так как этот параметр зависит от аргумента шаблона, компилятор не будет выполнять такие преобразования от вашего имени.

Другие вопросы по тегам