【发布时间】:2012-04-21 00:50:29
【问题描述】:
#include <iostream>
#include <thread>
using namespace std;
thread&& launch(){
thread launchee([](){
this_thread::sleep_for(chrono::milliseconds(280));
cout<<"HA!"<<endl;
});
return move(launchee);
}
int main(int argc, char **argv){
thread mine(launch());
mine.join();
}
用g++-4.6 -std=c++0x 1.cpp -o e1 -pthread编译
输出“在没有活动异常的情况下终止调用”,然后程序中止。
这应该有效,不是吗??
【问题讨论】:
-
右值引用仍然是引用。您不想返回对局部变量的引用。
标签: c++ multithreading c++11 move