3
我下面就穿一个在线教程,并得到了错误消息“的语义问题:尝试使用删除功能”?任何想法有什么错主题(尝试使用删除功能
#include <iostream>
#include <thread>
#include <string>
using namespace std;
class Fctor {
public:
void operator() (string & msg) {
cout << "t1 says: " << msg << endl;
msg = "msg updated";
}
};
int main(int argc, const char * argv[]) {
string s = "testing string " ;
thread t1((Fctor()), s);
t1.join();
return 0;
}
什么是完整错误? – 0x499602D2
由Fctor()构造的对象的活动时间不够长,无法在线程中使用。 – bmargulies
@bmargulies不,这很好。这是另一个参数's'的问题。我猜'std :: ref(s)'会起作用。 – juanchopanza