Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;方法使用方法启动线程_C++_Multithreading_Methods - Fatal编程技术网

C++ c++;方法使用方法启动线程

C++ c++;方法使用方法启动线程,c++,multithreading,methods,C++,Multithreading,Methods,我已经看到以下语法是正确的(或者我认为是正确的),但是带有microsoft c/c++扩展名的vscode在“A::ToThread”(在A.cpp文件中)之前的“&”下加了红色下划线,并表示: 构造函数“std::_u1::thread::thread”没有实例 匹配参数列表 这个程序“显然”有效,但我认为有些地方不对劲 守则: A.h A.cpp 这是一个vs代码高亮错误。你的代码是有效的,并且可以编译:@NathanOliver有没有办法退出这个bug,或者我必须经常看到这个警报?不确定

我已经看到以下语法是正确的(或者我认为是正确的),但是带有microsoft c/c++扩展名的vscode在“A::ToThread”(在A.cpp文件中)之前的“&”下加了红色下划线,并表示:

构造函数“std::_u1::thread::thread”没有实例 匹配参数列表

这个程序“显然”有效,但我认为有些地方不对劲

守则:

A.h

A.cpp


这是一个vs代码高亮错误。你的代码是有效的,并且可以编译:@NathanOliver有没有办法退出这个bug,或者我必须经常看到这个警报?不确定。我不使用VS代码,所以最好使用c++的经典visual studio(紫色的),另一种选择:
std::thread th(std::bind(&A::ToThread,这是“某物”)
class A{
public:
    void CreateThread();
    void ToThread(std::string s);
};
#include "A.h"
void A::CreateThread(){
    std::thread th(&A::ToThread, this, "something");
    th.detach();
}
void A::ToThread(std::string s){
    while(1){
        std::cout << s << std::endl;
    }
}
#include "A.h"
int main(){
    A a;
    a.CreateThread();
    while(1){}
    return 0;
}