Ich kann das folgende Programm nicht kompilieren.Warum std :: move funktioniert nicht mit std :: list
void toSin(std::list<double>&& list)
{
std::for_each(list.begin(), list.end(), [](double& x)
{
x = sin(x);
});
}
int main()
{
std::list<double> list;
const double pi = 3.141592;
const double epsilon = 0.0000001;
for (double x = 0.0; x < 2 * pi + epsilon; x = x + pi/16)
{
list.push_back(x);
}
// Start thread
std::thread th(toSin, std::move(list));
th.join();
return 0;
}
ich> Fehler C2664: 'void (std::list<double,std::allocator<_Ty>> &&)
': Konvertierung Argument 1 von 'std::list<double,std::allocator<_Ty>>
' auf 'std::list<double,std::allocator<_Ty>> &&
'
Reproduzieren kann ich nicht . Welche Version von Visual Studio verwenden Sie? Wohlgemerkt, ich habe ein paar fehlende Header hinzugefügt. – user4581301
Die Zeile 'std :: thread th (toSin, std :: move (list));' impliziert, dass Sie nicht über 'list' hinauslaufen sollten, da dieser weggerückt ist. Aber Sie versuchen, in der nächsten Zeile darüber zu iterieren. –
Visual Studio 2013 –