boost绑定模板错误
//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();
}
//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();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这样做有帮助吗?
存在从
boost::bind
返回的类型到boost::function
的转换,但由于此参数依赖于模板参数,因此编译器不会代表您进行任何此类转换。Does it help to do this?
There is a conversion from the type returned by
boost::bind
toboost::function<T()>
, but since this parameter depends on a template argument, the compiler won't do any such conversions on your behalf.