condition.wait_for智能感知错误
condition.wait_for intellisense error
我正在做一个基于线程的简单教程。在这个练习中,我应该让线程相互等待。我已经逐字复制了示例代码,除了我没有使用namespace std;
而是每次需要时都用std::
编写
有问题的错误对应于以下行:
if (condition.wait_for(std::unique_lock<std::mutex>(mut), std::chrono::seconds(3)))
Intellisense告诉我"表达式必须具有布尔类型(或可转换为布尔值)",但我查找了condition.wait_for
的文档,它可以返回std::cv_status::timeout
,std::cv_status::no_timeout
以及true
和false
。当我去建造时,它认为它只能返回std::cv_status
.
它应该可以工作吗?它是否需要第三个参数?我下面的示例没有使用。
正如Bo所说,该函数有两个版本。我将假设示例中有一个拼写错误,它意味着使用具有三个参数的函数版本,这是一些工作代码,我不知道它的工作方式是否与示例预期相同。
if (condition.wait_for(std::unique_lock<std::mutex>(mut), std::chrono::seconds(3), [] {return true; }))
相关文章:
- 警告处理为错误这里有什么问题
- "error: no matching function for call to"构造函数错误
- 设置我的应用程序 API 感知并防止系统使其模糊和错误定位
- 我在代码中有一个错误,错误是:(智能感知:不允许抽象类类型"HourlyWorker"的对象:)
- VS 2017 中的标头 cmath 智能感知错误
- 错误太多,智能感知引擎无法正常运行
- 我在C++文件中的简单代码块上有 2 个错误。错误 C2059:语法错误:"?"。第二智能感知:预期表达式。怎么了?
- condition.wait_for智能感知错误
- VS Express 2012 C++ lambda 智能感知错误
- 错误:智能感知:标识符"uint32"未定义?
- vector.push_back() 智能感知错误
- 智能感知说错误:成员"Class::field"无法访问,但它仍然有效?为什么?
- 预编译标头智能感知错误
- 无法使用大括号初始化智能感知错误调用基类构造函数
- 智能感知错误标识符"emlrtStack"未定义
- "Expected a c++ keyword" 在 atlbase.h 中 智能感知中的错误
- C++错误未声明的标识符,但殷智感知不显示错误
- 为什么sqrt()在智能感知中使用两个pow()的内部计算是错误的
- C++ 标准模板库的智能感知错误:<error-type>*?
- 映射和节点,错误智能感知:不存在从"const std::pair<const int, double>"到"Node"的合适用户定义转换