第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

c++11 auto遍歷存儲線程vector

c++11 auto遍歷存儲線程vector

GCT1015 2018-07-22 13:22:23
我這里已經(jīng)明白了是因為線程不能被復制#include <iostream>#include <thread>#include <vector>using namespace std;void Func() {    cout << "hello world" << endl; }int main() {    vector<thread> tmp;    for (int i = 0; i < 5; i++)      {         tmp[i] = thread(Func);     }    for (auto it : tmp)      {        //     } }于是我嘗試使用迭代器像這樣#include <iostream>#include <thread>#include <vector>using namespace std;void Func() {    cout << "hello world" << endl; }int main() {    vector<thread> tmp;    for (int i = 0; i < 5; i++)      {         tmp[i] = thread(Func);     }    for (auto it = tmp.begin(); it != tmp.end(); it++)      {         it->join();     } }但是運行結(jié)果得到段錯誤,請問是為什么
查看完整描述

2 回答

?
AAnonymous

TA貢獻62條經(jīng)驗 獲得超31個贊

錯誤貼出來

另外,你覺得 for (auto it : tmp) 有值拷貝的話,換成引用就沒有拷貝了 for (auto &it : tmp)

查看完整回答
反對 回復 2018-07-31
?
呼喚遠方

TA貢獻1856條經(jīng)驗 獲得超11個贊

最基本的問題。第一個循環(huán)里面對vector居然不用push_back

查看完整回答
反對 回復 2018-07-29
  • 2 回答
  • 0 關(guān)注
  • 1864 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號