std-function

    2熱度

    2回答

    我試圖實現的是std::list其中包含std::functions。我試圖實現一個回調系統,其中可以將函數添加到列表中,然後可以循環列表並調用每個函數。 我在A級是什麼: std::list<std::function<void(bool)>> m_callbacks_forward; bool registerForward(std::function<void(bool)> f) { m

    1熱度

    1回答

    我想在gcc 4.7.2上將一些代碼轉換爲C++ 11。部分代碼包括將boost::factory分配給boost::function。但是,如果我將其更改爲std::function,編譯失敗並伴有大量警告。下面是示例代碼重現錯誤: #include <boost/functional/factory.hpp> #include <boost/function.hpp> #include <

    1熱度

    1回答

    給定兩個explicit構造函數重載(根據不同std::function<...>類型)的std::bind返回值是能夠選擇要麼(從而使呼叫曖昧) call of overloaded ‘Bar(std::_Bind_helper<false, void (Foo::*)(int), Foo*, int>::type)’ is ambiguous 如果我註釋掉了,那麼代碼會編譯! 我

    6熱度

    1回答

    是否可以使用std :: async調用使用std :: bind創建的函數對象。下面的代碼無法編譯: #include <iostream> #include <future> #include <functional> using namespace std; class Adder { public: int add(int x, int y) { ret

    1熱度

    2回答

    我正在開發一個應用程序,我的想法是存儲「應用程序」的文件,如可執行文件。現在我有一個: AppWriter.c #include <vector> #include <time.h> #include <functional> struct PROGRAM { std::vector<int> RandomStuff; std::vector<std::function

    3熱度

    1回答

    我想知道是否有人可以請解釋如何,給定類型T和X,std::function需要T(X)作爲模板參數。 int(double)看起來像double通常投地int,所以std::function是如何解析它爲不同的類型? 我做了搜索,但沒有找到任何具體解決這個問題的東西。謝謝!

    2熱度

    1回答

    我有這樣的功能: void cb(void *obj) { if(nullptr != obj) { auto f = static_cast< function<void()>* >(obj); (*f)(); } } ,我使用這種方式: auto obj = new function<void()> (bind(&AClass::A

    0熱度

    1回答

    斷言可調用的最佳實踐是什麼與std::function兼容。它告訴可調用是否可以作爲參數傳遞,其中需要相對的std::function類型。 例子: int foo(int a) { return a; } auto bar = [](int a)->int { return a; } char baz(char a) { return a; } compatible(foo, std::

    1熱度

    1回答

    我想創建一個父類的版本的虛擬和重載函數的一個std ::函數對象,請看下面的例子: #include <iostream> #include <functional> class Parent { public: virtual void func1() { std::cout << "Parent::func1\n"; }

    6熱度

    1回答

    我想弄清楚std :: function在與閉包結合使用時會發生什麼。我現在還不能將自己的頭包裹起來,例如:正在調用哪個構造函數? 任何人都可以發佈一個minimalistic drop的工作示例來替換支持以下示例中所需功能的std :: function: #include <functional> int main(int argc, char* argv[]) { int m