[问题] 一段语法询问

楼主: gecer (gecer)   2018-03-24 08:53:15
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?
作者: stupid0319 (征女友)   2018-03-24 09:05:00
自动指定类型?
作者: steve1012 (steve)   2018-03-24 09:16:00
让编译器推导type 跟你想说的一样
作者: jerryh001   2018-03-24 09:38:00
"auto"是自动推定 那一整段的写法是forloop*foreach loop

Links booklink

Contact Us: admin [ a t ] ucptt.com