This question already has an answer here:
I'm getting the error when creating a thread. I guess I'm not clear about how C++ implicitly use the "delete" function. Following is the program, I declared a struct, a function, and the main:
struct refo {
int n;
refo(int m):n(m) {
auto id = this_thread::get_id();
cout << id << ":created:" << n << endl;
}
~refo() {
auto id = this_thread::get_id();
cout << id << ":destroyed" << n << endl;
}
}
void testReference2(vector<refo>& v) {
this_thread::sleep_for(chrono::seconds(3));
cout << "v size:" << v.size() << endl;
}
int main() {
vector<refo> v;
std::thread t(testReference2, v); //<--- error here
t.join();
return 0;
}
But I'm getting a link error: /Applications/http://ift.tt/1MCHFEE: error: attempt to use a deleted function
I guess this is C++ newbie question but thanks for any help!
Aucun commentaire:
Enregistrer un commentaire