具有来自另一个类

时间:2017-08-30 15:13:31

标签: c++ multithreading c++11

有人能告诉我如何从不同类的对象作为此类的成员函数运行带有成员函数的新线程?我试图做什么我仍然得到错误。

  

no match for call to '(std::thread) (void (Boo::*)(), Boo&)'|
  no match for call to '(std::thread) (void (Foo::*)(), Foo*)'|

#include <iostream>
#include <thread>
using namespace std;
class Boo
{
public:
    void run()
    {
        while(1){}
    }
};

class Foo
{
public:
    void run()
    {
        t1(&Boo::run,boo);
        t2(&Foo::user,this);
    }
    void user();
    ~Foo(){
        t1.join();
        t2.join();
    }
private:
    std::thread t1;
    std::thread t2;
    Boo boo;
};
int main()
{
    Foo foo;
    foo.run();
}

1 个答案:

答案 0 :(得分:4)

您需要在构建后使用schema { query: Query } type Query { documents: [Document!]! document(id: Int): Document! } interface Document { id: Int! title: String! } type Article implements Document { id: Int! title: String! featured: Boolean! sections: [ArticleSection!]! } union ArticleSection = TextSection | PhotoSection | VideoSection type TextSection { content: String! heading: String } type PhotoSection { sourceUrl: String! linkUrl: String caption: String content: String } type VideoSection { url: String! } type Roundup implements Document { id: Int! title: String! isAward: Boolean! intro: String hotels: [RoundupHotel!]! } type RoundupHotel { url: String! photoUrl: String @deprecated(reason: "photoUrl is deprecated; use photos") photos: [RoundupPhoto!]! blurb: String! title: String } type RoundupPhoto { url: String! caption: String } 分配线程

下面的工作示例(see it in action):

operator=