2010-08-12 5 views
0
//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(); 
} 
+0

[i-hate-C++]: C++ n'est pas si mauvais, du moins ce n'est pas Java. – James

+0

Je vous vois édité dans ma suggestion, mais j'avais tort, désolé. – Thomas

+0

thx de toute façon, ça ne fait pas mal, donc je vais le laisser –

Répondre

2

Cela aide-t-il de le faire?

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

Il y a une conversion du type retourné par boost::bind à boost::function<T()>, mais étant donné que ce paramètre dépend d'un argument modèle, le compilateur ne fera pas ces conversions en votre nom.

Questions connexes