c++ - 没有构造函数“std::thread::thread”的实例与参数列表匹配——参数类型为:(void ())
问题描述
我正在尝试使用线程同时在 2 个不同的函数中运行 2 个 while 循环,但我收到如下错误::。错误:no instance of constructor "std::thread::thread" matches the argument list -- argument types are: (void ())
我尝试加入和分离线程,但也没有用。
class Parallel {
public:
int attempts = 0;
int rs = 0;
int threads = 0;
int before = 0;
void RS(){
while(true) {
before = attempts;
Sleep(1000);
rs = attempts - before;
}
}
void Print() {
while(true) {
attempts++;
cout << "\r" << "Attempts: " << attempts << " RS: " << rs;
}
}
void thread2(){
thread first (Print());
thread second (RS());
}
};
int main(){
Parallel j;
j.thread2();
return 0;
}
解决方案
推荐阅读
- mysql - 试图获得每个州的总约会。在 MySQL 1055 中出现错误
- cassandra - 无法识别的 VM 选项“UseParNewGC”错误:无法创建 Java 虚拟机。同时设置 apache-cassandra-3.11.8
- batch-file - 使用 bat 文件从 1 .txt 中提取内容保存到另一个 .txt
- c# - 为什么我不能引用 ICollection 中的属性?
- java - 需要帮助从 java 中的文本文件中获取数据。我需要找到最高价格以及与价格相关的数据
- mysql - 为什么我的 SQL 查询在 MySQL 工作台中失败?
- python - While 语句在四点停止
- ios - 如何将 H.264 压缩应用于 CMSampleBuffer
- javascript - 购物车页面价格计算问题,逗号不显示总价格 $ NaN
- machine-learning - 预测一段时间内的客户流失