stdbind

    1熱度

    1回答

    我想了解std::bind。我寫了下面的程序。 #include <memory> #include <functional> #include <iostream> #include <algorithm> using namespace std::placeholders; int a

    1熱度

    1回答

    我遇到一個錯誤,當使用模板類型演繹結合C++ 14 std ::得到<>與類型索引。代碼可能看起來有點複雜,但我試圖將其簡化爲對正在發生的事情的基本知識。它實際上只是一個Observer模式...結構'A'允許根據消息類型(M1,M2,...)設置觀察者。請注意,每個消息類型只有一個觀察者,爲了簡單起見。 現在,技巧(以及失敗的部分)正在使用C++ 14的std :: get <>,它允許您使用實

    1熱度

    1回答

    我想通過公共函數將回調函數連接到boost信號。我可以傳遞一個函數指針,但如果我嘗試使用std :: bind來傳遞成員函數,它將不會編譯。給我錯誤說沒有可行的轉換。我應該使用什麼類型的App :: SetCallback函數參數? #include <functional> #include <boost/signal.hpp> using namespace std::placeholde

    1熱度

    2回答

    對於結構後: struct A { int var = 10; void check() { std::cout << "var is " << var << std::endl; } }; 說我創建的A::check()一個std ::功能對象,使用動態分配的a對象: auto a_ptr = std::make_unique<A>(); std

    0熱度

    1回答

    的所以,我有一類稱爲代表能夠存儲函數指針陣列。這是代碼: template<typename Func> class delegate { private: public: typename std::vector<Func> mListOfFunctions; void Bind(Func f) { mListOfFunctions.push_b

    4熱度

    3回答

    我目前正在使用std::bind從函數模板 template<class Iterator> void printRange(Iterator first, Iterator last) { std::copy(first, last, std::ostream_iterator<typename Iterator::value_type>(std::cout, " "));

    1熱度

    1回答

    以下代碼使用Xcode 6.3.2在OS X上編譯併成功運行。但是,它在使用VS2013的Windows上運行時會崩潰。 #include <vector> #include <string> #include <memory> #include <functional> #include <iostream> void validate(const std::string& name

    1熱度

    2回答

    將一個類的成員函數傳遞給另一個類的std::function的正確方法是什麼? 例如,下面的Bar想存儲一個Foo對象的函數。 class Foo { public: Foo(int x) : data(x) {} bool isEven(int y) { return (data + y) & 0x01; } int data; }; class Bar {

    1熱度

    1回答

    我想使用std :: bind和typecast函數參數與typedef函數一起使用。但是,我不能強制轉換std ::佔位符。任何想法來實現我想要做的事情?出於各種原因,我需要能夠使typedef函數具有uint16_t參數,並且還需要init函數接受一個採用uint8_t參數的成員函數)。我使用的代碼(編輯爲簡單起見): typedef void (write_func_t) (uint16_t

    1熱度

    1回答

    當函數對象被異步調用時,將std::shared_ptr傳遞給std::bind安全嗎? I.E.大致如下安全: // Copy do not reference shared_ptr void someFunc(std::shared_ptr<Something> arg1,...other args...); std::shared_ptr<Something> data; // Thi