【发布时间】:2014-02-26 16:56:45
【问题描述】:
我有一个派生类,我从该派生类中绑定了一个未在此类中覆盖的虚函数,因此我希望调用父类中的一个。
它适用于 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 Base::* )(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 有什么关系。
也检查了 stroustrup 的网站here,但我没有看到任何可以解释这种行为的东西。
我在这里错过了什么?
Ps:我使用 VS2012 Update 4,如果这可以帮助的话
【问题讨论】:
-
this 有效吗?如果不是,则可能是标准库实现之一中的错误。
-
不编译,不行。
标签: c++ visual-studio-2012 c++11 boost-bind stdbind