日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

_M_invoke(_Index_tuple_Indices...)

發布時間:2023/12/10 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 _M_invoke(_Index_tuple_Indices...) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

[hadoop@iZ25s7cmfyrZ C_script]$ cat test_thread_a.cpp #include <iostream> #include <atomic> #include <thread> #include <vector>std::atomic<int> global_counter(0);void increase_global (int n){for (int i=0; i< n; ++i)++global_counter; }void increase_reference(std::atomic<int>& variable, int n){for (int i=0;i<n; ++i)++variable; }struct C:std::atomic<int>{C():std::atomic<int>(0){}void increase_member(int n){for(int i=0;i<n;++i)fetch_add(1);} };int main(int argc, char** argv){std::vector<std::thread> threads;std::cout << "Increase global counter with 10 threads...." << std::endl;for(int i=0;i<10;++i)threads.push_back(std::thread(increase_global, 1000));std::cout << "Increase counter (foo) with 10 threads using reference...\n";std::atomic<int> foo(0);for(int i=0;i<10;++i)threads.push_back(std::thread(increase_reference, std::ref(foo), 1000));std::cout << "Increase counter (bar) with 10 threads using member...\n";C bar{};for(int i=0;i<10;++i){threads.push_back(std::thread(&C::increase_member,std::ref(bar),1000));}std::cout << "synchronizing all threads...\n";for(auto& th:threads) th.join();std::cout << "global: " << global_counter << std::endl;std::cout << "foo: " << foo << std::endl;std::cout << "bar: " << bar << std::endl; }

使用 ?g++ 編譯上面的代碼,結果因為存在歧義 將C bar{}(注有無{}都報這個錯誤) 將bar理解成一個 返回C 類型的函數, 文章中說https://en.wikipedia.org/wiki/Most_vexing_parse, 在c++11中已經修復這個錯誤,就是在 變量后面添加花括號, 但是沒有用依然報錯,

In file included from /usr/include/c++/4.8.2/thread:39:0,from test_thread_a.cpp:3: /usr/include/c++/4.8.2/functional: In instantiation of ‘struct std::_Bind_simple<std::_Mem_fn<void (C::*)(int)>(std::reference_wrapper<C>, int)>’: /usr/include/c++/4.8.2/thread:137:47: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (C::*)(int); _Args = {std::reference_wrapper<C>, int}]’ test_thread_a.cpp:42:77: required from here /usr/include/c++/4.8.2/functional:1697:61: error: no type named ‘type’ in ‘class std::result_of<std::_Mem_fn<void (C::*)(int)>(std::reference_wrapper<C>, int)>’typedef typename result_of<_Callable(_Args...)>::type result_type;^ /usr/include/c++/4.8.2/functional:1727:9: error: no type named ‘type’ in ‘class std::result_of<std::_Mem_fn<void (C::*)(int)>(std::reference_wrapper<C>, int)>’_M_invoke(_Index_tuple<_Indices...>)

后來改用 clang++ 編譯沒有出現這個錯誤,特此記錄

轉載于:https://my.oschina.net/lCQ3FC3/blog/1359284

總結

以上是生活随笔為你收集整理的_M_invoke(_Index_tuple_Indices...)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。