【问题标题】:how to call a function pointer via boost thread如何通过boost线程调用函数指针
【发布时间】:2015-02-05 05:47:07
【问题描述】:

class A { public: int xx(int size) { } public: int xx(int size) { } int yy(int size) { } }; int main() { typedef int (A::*functions)(int); std::vector<functions> methods = { &A::xx, &A::yy }; A aa; boost::thread_group thgrp; for (typename std::vector<functions>::iterator itr=methods.begin();itr!=methods.end();++itr) { functions z=*itr; boost::thread *t=new boost::thread(z,aa,10); thgrp.add_thread(t); } thgrp.join_all(); return 0; }

我收到一个错误“没有匹配的函数调用'get_pointer'”。 我想使用 boost 线程从我的预定义类型的向量中调用方法。

请帮我解决这个问题!

【问题讨论】:

  • 也许发送&amp;aa
  • ...这不是有效的 C++ 代码。 A 类有两个成员,它们具有相同的名称 (xx) 和签名 (int)。 xxyy 都没有返回任何内容,但被声明为这样做。

标签: c++ boost boost-thread


【解决方案1】:

对不起!!!

我发现我做错了!此代码运行正常!
我用对象“方法”而不是类“aa”的对象调用 boost::thread。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-24
    • 1970-01-01
    • 2016-09-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多