看板 C_and_CPP 關於我們 聯絡資訊
http://www.cplusplus.com/reference/mutex/mutex/lock/ // mutex::lock/unlock #include <iostream> // std::cout #include <thread> // std::thread #include <mutex> // std::mutex std::mutex mtx; // mutex for critical section void print_thread_id (int id) { // critical section (exclusive access to std::cout signaled by locking mtx): mtx.lock(); std::cout << "thread #" << id << '\n'; mtx.unlock(); } int main () { std::thread threads[10]; // spawn 10 threads: for (int i=0; i<10; ++i) threads[i] = std::thread(print_thread_id,i+1); for (auto& th : threads) th.join(); return 0; } 請問黃字 auto 的意思? 是不是等於foreach loop? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.255.14.8 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1521852798.A.4BB.html ※ 編輯: gecer (111.255.14.8), 03/24/2018 08:53:29 ※ 編輯: gecer (111.255.14.8), 03/24/2018 08:53:44 ※ 編輯: gecer (111.255.14.8), 03/24/2018 08:54:19
stupid0319: 自動指定類型? 03/24 09:05
steve1012: 讓編譯器推導type 跟你想說的一樣 03/24 09:16
jerryh001: "auto"是自動推定 那一整段的寫法是forloop 03/24 09:38
jerryh001: *foreach loop 03/24 09:39