关于Boost Asio,我是一个新手。我玩过回调,并且一切正常。但是,现在我正尝试切换到协程,并且co_await
遇到了问题。 Visual Studio 2017社区版显示"this co_await expression requires a suitable "await_ready" function and none was found"
。
我使用的代码是Boost Asio网站上作者的示例。链接:
https://www.boost.org/doc/libs/1_69_0/doc/html/boost_asio/example/cpp17/coroutines_ts/echo_server.cpp
我对代码所做的唯一修改是文件第一行的#define BOOST_ASIO_HAS_CO_AWAIT
。
为什么每次出现"this co_await expression requires a suitable "await_ready" function and none was found"
时都会出现此错误co_await
?作者的示例应该可以正常工作,对吗?我是否缺少#include
或其他内容?
任何帮助,不胜感激。
最佳答案
感谢Orbit中的Lightness Races建议您尝试使用编译器切换,这是主要问题,尽管我还有其他问题。如果有人遇到类似问题,请按照以下步骤操作:
#define BOOST_ASIO_HAS_CO_AWAIT
移至头文件pch.h(愚蠢的错误)/await
开关添加到Project Properties > C/C++ > Command Line > Additional Options
。 至此,所有内容编译都没有错误。但是,
co_await
仍然带有红色下划线,原因是:资料来源:https://blogs.msdn.microsoft.com/vcblog/2017/05/19/using-c-coroutines-with-boost-c-libraries/
关于c++ - Visual Studio在作者的Boost Asio示例中提示co_await,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54112309/