我遇到了关于c ++ 11并发(第3部分)的Youtube视频和以下代码,它们在视频中编译并生成正确的结果.
但是,我使用Visual Studio 2012得到了此代码的编译错误.编译器抱怨参数类型为toSin(list<double>&&).如果我将参数类型更改为list<double>&,则编译代码.
我的问题是从中返回move(list)的内容_tmain(),它是右值引用还是仅仅是引用?
#include "stdafx.h"
#include <iostream>
#include <thread>
#include <chrono>
#include <list>
#include <algorithm>
using namespace std;
void toSin(list<double>&& list)
{
//this_thread::sleep_for(chrono::seconds(1));
for_each(list.begin(), list.end(), [](double & x)
{
x = sin(x);
});
for_each(list.begin(), list.end(), [](double & x)
{
int count = static_cast<int>(10*x+10.5);
for (int i=0; i<count; ++i)
{
cout.put('*');
}
cout << endl;
});
}
int _tmain(int argc, _TCHAR* argv[])
{
list<double> list;
const double pi = …Run Code Online (Sandbox Code Playgroud) c++ rvalue-reference move-semantics c++11 visual-studio-2012