【发布时间】:2014-05-21 17:28:20
【问题描述】:
我正在尝试将 std::function 与这样的成员函数一起使用:
struct Foo
{
void bar(int) const { /* ... */ }
};
//later on
std::function<void(const Foo&, int)> fun = &Foo::bar;
这在 GCC 4.8.1 下有效,但在 VS2013 下编译失败,出现以下错误:
error C2664: 'void std::_Func_class<_Ret,const Foo &,int>::_Set(std::_Func_base<_Ret,const Foo &,int> *)' :
cannot convert argument 1 from '_Myimpl *' to 'std::_Func_base<_Ret,const Foo &,int> *'
在我看来,它就像 VS 中的一个错误,但也许我什么也没看到?有没有办法解决它(没有像 boost 这样的外部库)?
编辑:我在条形签名中忘记了“const”。但这在 VS 中仍然不起作用。
【问题讨论】:
标签: c++ visual-studio-2013 std-function member-functions