C++,Linux:错误:从'boost :: unique_future <void>'转换为请求的非标量类型'boost :: shared_future <void>'.怎么绕过它?

Rel*_*lla 5 c++ boost future scheduled-tasks boost-thread

我尝试使用提升线程期货.如图所示,我们可以从打包任务中获得共享的未来.

所以我在linux上尝试这样的功能:

template <class task_return_t>
void pool_item( boost::shared_ptr< boost::packaged_task<task_return_t> > pt)
{
    boost::shared_future<task_return_t> fi= pt->get_future(); // error
    //...
Run Code Online (Sandbox Code Playgroud)

但我收到错误称:

../../src/cf-util/thread_pool.h: In member function ‘void thread_pool::pool_item(boost::shared_ptr<boost::packaged_task<R> >) [with task_return_t = void]’:
../../src/cf-util/thread_pool.h:64:3:   instantiated from ‘void thread_pool::post(boost::shared_ptr<boost::packaged_task<R> >) [with task_return_t = void]’
../../src/cf-server/server.cpp:39:27:   instantiated from here
../../src/cf-util/thread_pool.h:124:58: error: conversion from ‘boost::unique_future<void>’ to non-scalar type ‘boost::shared_future<void>’ requested
Run Code Online (Sandbox Code Playgroud)

我之前没有接受任何期货.所有的源代码,地方,我从打电话,那是被称为我的线程池.在Visual Studio 2010下的Windows上,它可以完美地编译和工作.

我该怎么办?如何修复或解决此错误?

tgo*_*art 0

您是否可能忘记包含正确的标题?

如果没有,像下面这样的不同构造函数可以工作吗?

boost::shared_future<task_return_t> fi(pt->get_future());
Run Code Online (Sandbox Code Playgroud)