该方法validate(std::string& request, int& id)返回bool.
当我使用这种语法时,编译完成:
auto task_1 = std::async([&]{ validate(request, id); });
Run Code Online (Sandbox Code Playgroud)
但是,当我使用时std::future<bool>,编译失败:
std::future<bool> task_1 = std::async([&]{ Internal::validate(request, id); });
Run Code Online (Sandbox Code Playgroud)
错误是:
错误:请求从'
std::future<void>' 转换为非标量类型'std::future<bool>'
这有什么不对?我想检查一下:
task_1.get() == true
Run Code Online (Sandbox Code Playgroud)
更改
std::future<bool> task_1 = std::async([&]{ Internal::validate(request, id); });
Run Code Online (Sandbox Code Playgroud)
至
std::future<bool> task_1 = std::async([&]{ return Internal::validate(request, id); });
Run Code Online (Sandbox Code Playgroud)
你的lambda没有返回bool; 所以它不能用作未来的来源bool.
如果validate不归bool,那应该是future<void>.