这里部分回答了这个问题 What does "typedef void (*Something)()" mean
但我并不完全清楚答案。
如果我写
typedef void (*task) ();
它是如何展开的?
thread_pool(unsigned int num_threads, task tbd) {
for(int i = 0; i < num_threads; ++i) {
the_pool.push_back(thread(tbd));
}
}
会不会像这样?
thread_pool(unsigned int num_threads, (*task) () tbd) {
for(int i = 0; i < num_threads; ++i) {
the_pool.push_back(thread(tbd));
}
}
可能不是,因为这是一个语法错误。我希望你能帮我解决问题。
代码示例来自http://www.thesaguaros.com/openmp-style-constructs-in-c11.html
最佳答案
是这样的:
thread_pool(unsigned int num_threads, void (*tbd) ())
也就是说,类型是函数签名,其中唯一的“词”是“void”。 typedef 名称“task”在此示例中消失了,因为我们不再使用 typedef。
关于c++ - "typedef void (*task) ()"是做什么的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14788255/