2013-02-09 38 views
0

这个问题部分解答了这里What does "typedef void (*Something)()" mean“typedef void(* task)()”是做什么的?

但是答案并不完全清楚。

如果我写

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

回答

2

是这样的:

thread_pool(unsigned int num_threads, void (*tbd)()) 

也就是说,类型是函数签名,唯一的“词”中,这是“无效”。在这个例子中,typedef名称“task”消失了,因为我们不再使用typedef。

+0

谢谢,现在它是有道理的。 – 2013-02-09 12:47:36

相关问题