2013-02-09 39 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

相關問題