我正在尝试运行以下简单示例。
void printString(const char* s)
{
std::cout << s << std::endl;
}
int main()
{
std::string str = "hello world";
std::thread T3(printString,str.c_str());
}
但是出现以下错误。
No matching constructor for initialization of 'std::thread'
我正在使用Xcode 11.1。
如果要编译,那么此代码是否还能工作?由于线程共享同一堆,因此线程T3
应该能够访问str.c_str()
,对吗?假设std::string
缓冲区是在堆上分配的。
谢谢!