//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(); }
这样做有帮助吗?
return get_wrapper<BSTR>(pVal, boost::bind(&CAttributeValue::getNameCOM, this)); // ^^^^^^
存在从返回的类型的转换 boost::bind 到 boost::function<T()> 但是,由于这个参数依赖于一个模板参数,编译器不会为您进行任何这样的转换。
boost::bind
boost::function<T()>