[問題] 一段語法詢問

看板C_and_CPP (C/C++)作者 (gecer)時間8年前 (2018/03/24 08:53), 8年前編輯推噓4(402)
留言6則, 4人參與, 8年前最新討論串1/1
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

03/24 09:05, 8年前 , 1F
自動指定類型?
03/24 09:05, 1F

03/24 09:16, 8年前 , 2F
讓編譯器推導type 跟你想說的一樣
03/24 09:16, 2F

03/24 09:21, 8年前 , 3F

03/24 09:21, 8年前 , 4F

03/24 09:38, 8年前 , 5F
"auto"是自動推定 那一整段的寫法是forloop
03/24 09:38, 5F

03/24 09:39, 8年前 , 6F
*foreach loop
03/24 09:39, 6F
文章代碼(AID): #1QjQ5-Ix (C_and_CPP)
文章代碼(AID): #1QjQ5-Ix (C_and_CPP)