2014-02-26 63 views
4

我有一個派生類,從中我綁定了一個虛擬函數,我沒有在這個類中重寫,所以我希望調用其中一個父類。
它與提升(1.55)不錯,但如果我切換到標準::從C++ 11綁定,它拒絕與std :: bind和boost :: bind與多態之間的區別

錯誤C2100編譯:非法間接 1>功能(1152):見參考起作用模板實例 '_Rx的std :: _ Pmf_wrap < _Pmf_t,_Rx,_Farg0,_V0_t,_V1_t,_V2_t,_V3_t,_V4_t,_V5_t,> ::運算符()(_包裝&)const的' 被編譯 1>使用 1> [ 1> _Rx = BOOL, 1> _Pmf_t =布爾(__thiscall基地:: *)(無效), 1> _Farg0 =基地 1> _V0_t =標準:: _無, 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 :: _無, 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 

這不是一個大問題,因爲我可以有增強堅持,但我真的很想知道這兩者之間的區別。

我在這裏檢查了幾個問題,但我不認爲它將如何與this相關。 也檢查了stroustrup的網站here,但我沒有看到任何可以解釋此行爲的東西。
我在這裏錯過了什麼?

PS:我用VS2012更新4工作,如果這能幫助

+0

[this](http://coliru.stacked-crooked.com/a/1efb5c2d542e5958)是否有效?如果不是,它可能是標準庫實現中的一個錯誤。 – chris

+0

它不編譯,不。 – Kiroxas

回答

2

的Visual Studio 2012有很多關於std::functionstd::bind錯誤。這是其中之一;該代碼將同時在Visual Studio 2010和Visual Studio 2013中運行。

最好的選擇是僅使用Boost.Function和Boost.Bind。