我有一个派生类,从中绑定了一个我没有在此类中重写的虚函数,因此我希望调用父类中的一个。
它与 boost (1.55) 配合得很好,但如果我从 C++11 切换到 std::bind,它会拒绝编译
错误 C2100:非法间接寻址
1> 功能(1152):参见函数模板实例化'_Rx std::_Pmf_wrap<_pmf_t>::operator ()(_Wrapper &) const'正在编译
1> 与
1> [
1> _Rx=布尔值,
1> _Pmf_t=bool (__thiscall 基::* )(void),
1> _Farg0=基础,
1> _V0_t=std::_Nil,
1> _V1_t=std::_Nil,
1> _V2_t=std::_Nil,
1> _V3_t=std::_Nil,
1> _V4_t=std::_Nil,
1> _V5_t=std::_Nil,
1> =std::_Nil,
1> _Wrapper=派生
1>]
这是最小代码
class Runnable { virtual bool Run() =0;};
class Base : public Runnable { bool Run() {/*do stuff*/ return true;}};
class Derived : public Base {};
Derived d;
std::function<bool()> f = std::bind(&Derived::Run,std::ref(d)); //Do not compile
std::function<bool()> f = boost::bind(&Derived::Run,boost::ref(d)); //compile
这不是一个主要问题,因为我可以坚持使用 boost,但我真的很想知道两者之间有什么区别。
我在这里检查了几个问题,但我不认为它与this https://stackoverflow.com/questions/10555566/is-there-any-difference-between-c11-stdbind-and-boostbind。
也检查了 stroustrup 的网站here http://www.stroustrup.com/C++11FAQ.html#std-function,但我没有看到任何可以解释这种行为的东西。
我在这里缺少什么?
PS:我使用VS2012 Update 4,如果这可以帮助
Visual Studio 2012 有很多与以下相关的错误std::function
and std::bind
。这是其中之一;该代码可在 Visual Studio 2010 和 Visual Studio 2013 中运行。
最好的选择是单独使用 Boost.Function 和 Boost.Bind。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)