【发布时间】:2015-11-24 13:35:31
【问题描述】:
我的代码是这样的:-
#include <iostream>
#include <thread>
using namespace std;
void swapno (int &a, int &b)
{
int temp=a;
a=b;
b=temp;
}
int main()
{
int x=5, y=7;
cout << "x = " << x << "\ty = " << y << "\n";
thread t (swapno, x, y);
t.join();
cout << "x = " << x << "\ty = " << y << "\n";
return 0;
}
此代码无法编译。谁能帮我解决为什么?
不仅此代码,而且this 中的代码也未能通过引用发送std::unique_ptr。 std::thread 有什么问题?
【问题讨论】:
-
您可以通过使用
std::ref(即thread t (swapno, std::ref(x), std::ref(y));)来明确引用。
标签: c++ multithreading reference