std-future

    5熱度

    1回答

    考慮下面的源代碼 #include <thread> #include <future> #include <iostream> #include <string> #include <chrono> int main() { auto task = std::async(std::launch::async, [] { std::this_thread::s

    1熱度

    1回答

    我試圖製作一個視頻播放器。我已經添加了一個線程來計算視頻應該在屏幕上顯示的時間。我試圖在主線程中解碼視頻和更新窗口;第二個線程將獲取數據包,查看數據包應該顯示多長時間,然後將數據包發送到主線程,然後等待一段時間。 出於某種原因,我得到這個錯誤: terminate called after throwing an instance of 'std::future_error' what(

    13熱度

    2回答

    我剛纔讀: Lazy Evaluation in C++ ,發現它是一種古老而大部分的答案把前2011 C++。這些天來,我們有語法lambda表達式,甚至可以推斷返回類型,這麼懶的評價似乎歸結爲只是路過他們身邊:與其 auto x = foo(); 你執行 auto unevaluted_x = []() { return foo(); }; ,然後評估時, /你需要的地方: auto

    0熱度

    1回答

    爲什麼不讓這樣的線程在抽象基類中工作?我試圖抽象出從這個基類派生的用戶的所有多線程細節。當我明確寫出callbackSquare返回類型int時,我不明白它爲什麼說「沒有類型命名爲'type'」。 #include <iostream> #include <future> #include <vector> class ABC{ public: std::vector<std: