首页 > 解决方案 > 没有构造函数“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;
}

标签: c++

解决方案


推荐阅读