【问题标题】:What does "typedef void (*task) ()" do?“typedef void (*task) ()”有什么作用?
【发布时间】:2013-01-25 03:28:28
【问题描述】:

这个问题在这里得到了部分回答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

【问题讨论】:

    标签: c++ typedef


    【解决方案1】:

    是这样的:

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

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

    【讨论】:

    • 谢谢,现在说得通了。
    猜你喜欢
    • 1970-01-01
    • 2011-04-28
    • 1970-01-01
    • 2011-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多