Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用函子';使用boost::thread_Boost_Functor - Fatal编程技术网

如何使用函子';使用boost::thread

如何使用函子';使用boost::thread,boost,functor,Boost,Functor,如果我有一个像这样的函子 class DoStuff { private: std::vector < int > numericStuff; public: explicit DoStuff (const std::vector <int> &newStuff) : numericStuff (newStuff) {}; int operator () (void) { int ProcessedStuf

如果我有一个像这样的函子

class DoStuff {

  private:

    std::vector < int > numericStuff;

  public:

    explicit DoStuff (const std::vector <int> &newStuff) : numericStuff (newStuff) {};

    int operator () (void) {

       int ProcessedStuff = 0;

       //...Doing stuff

       return ProcessedStuff;

    };

};
DoStuff stuff (Vector);
boost::thread (stuff);
…就这样。我想做的是把它放到一个boost::线程中,就像这样

class DoStuff {

  private:

    std::vector < int > numericStuff;

  public:

    explicit DoStuff (const std::vector <int> &newStuff) : numericStuff (newStuff) {};

    int operator () (void) {

       int ProcessedStuff = 0;

       //...Doing stuff

       return ProcessedStuff;

    };

};
DoStuff stuff (Vector);
boost::thread (stuff);
…然后使用它,但就我个人而言,我不知道如何使用它。任何帮助都将不胜感激。

你不能这样做。要从线程“返回值”,必须使用。 引用上述文件:

当调用打包任务时,它将调用包含的函数 反过来,并用返回值填充未来这是一个 回答长期存在的问题:“如何从 线程?:打包您希望作为线程运行的函数 boost::打包的任务并将打包的任务传递给线程 构造器。从打包任务中检索到的未来可以 用于获取返回值。如果函数抛出异常, 它存储在将来的返回值的位置


我明白了,谢谢。我是boost新手,我在阅读线程文档时没有领会到这一点。我想我最好去了解一下未来。