Boost找不到未来::然后从demo

Pao*_*aJ. 8 c++ boost boost-thread

我想尝试提升未来,我已经安装了1.55并包含在make文件中,我想尝试官方演示

#define BOOST_THREAD_PROVIDES_FUTURE

#include <boost/thread/future.hpp>

using namespace boost;

int main()
{
  future<int> f1 = async([]() { return 123; });
  future<int> f2 = f1.then([](future<int> f) { return f.get();} );// here .get() won't block });
} 
Run Code Online (Sandbox Code Playgroud)

但我在编译期间总是遇到错误

error: ‘class boost::future<int>’ has no member named ‘then’
Run Code Online (Sandbox Code Playgroud)

当我用f2评论它时,它编译.

Aki*_*shi 10

你应该定义

#define BOOST_THREAD_VERSION 4
Run Code Online (Sandbox Code Playgroud)

要么

#define BOOST_THREAD_PROVIDES_FUTURE_CONTINUATION
Run Code Online (Sandbox Code Playgroud)