boost-bind

    3熱度

    3回答

    我有一些(庫API,所以我不能改變的函數原型),這是寫了下面的方法功能:現在 void FreeContext(Context c); ,在我執行我的一些時刻有Context* local_context;變量,這也是不改變。 我希望用boost::bind與FreeContext功能,但我需要從本地變量Context*檢索Context。 如果我寫我的代碼如下方式,編譯器說,這是「非法的間接

    2熱度

    3回答

    我必須將函數傳遞到指針。爲此,我使用boost :: function。捕獲指針的函數對於不同的簽名來說是過載的。例如: void Foo(boost::function<int()>) { ... } void Foo(boost::function<float()>) { ... } void Foo(boost::function<double()>) { ... } 現在我想通過一

    1熱度

    1回答

    下面的代碼在罰球線一個錯誤的位置我想創建的Test::fun2仿函數對象: #include <boost/shared_ptr.hpp> #include <boost/bind.hpp> #include <boost/function.hpp> using namespace boost; class Test { public: float fun1() { retur

    13熱度

    4回答

    有人能夠用幾個簡潔的詞彙總結應該如何使用智能指針,特別是從使用綁定函數在io_service中註冊處理程序的角度來看。 編輯:一些響應要求更多的上下文。基本上,我正在尋找「陷阱」,人們用這種機制觀察到的反直覺行爲。

    3熱度

    1回答

    鑑於A類, class A { public: A(B&) {} }; 我需要一個boost::function<boost::shared_ptr<A>(B&)>對象。 我不想建立一個特設的功能 boost::shared_ptr<A> foo(B& b) { return boost::shared_ptr<A>(new A(b)); } 解決我的問題,我試圖

    2熱度

    2回答

    像語義學我想能夠擁有像C++的Java接口語義。起初,我曾使用boost::signal爲給定事件回調顯式註冊的成員函數。這工作得很好。 但是後來我決定一些函數回調池是相關的,抽象它們並立即註冊一個實例的所有相關回調是有意義的。但是我學到的是boost::bind的具體性質和/或採取this的價值似乎使這個突破。或者,也許這只是add_listener(X &x)方法聲明更改boost::bind

    1熱度

    1回答

    我想讓這段代碼正常工作,我該怎麼辦? 在最後一行發生此錯誤。 我做錯了什麼? 我知道boost :: bind需要一個類型,但我沒有得到。幫助 class A { public: template <class Handle> void bindA(Handle h) { h(1, 2); } }; class B {

    3熱度

    2回答

    假設我有一個函數,它接受一個零元函子作爲參數: void enqueue(boost::function<void()> & functor); 我有另一個功能,其採用int和做了內部: void foo(int a); 我想窩,但讓我得到簽名函子不構成,這些結合在一起: boost::function<void(int)> functor 當與一個叫價值 - 說4 - 執行以下操作:

    7熱度

    1回答

    我想了解下面的示例中,類似(但不等於)給一個在SO Help understanding boost::bind placeholder arguments早些時候發佈: #include <boost/bind.hpp> #include <functional> struct X { int value; }; int main() { X a = { 1 }

    2熱度

    4回答

    我想使用std :: for_each將一系列字符串添加到組合框。對象的類型爲Category,我需要在其上調用GetName。我如何用boost::bind實現這個目標? const std::vector<Category> &categories = /**/; std::for_each(categories.begin(), categories.end(), boost::bind(