永发信息网

C++的std:thread是怎么进行参数传递的

答案:2  悬赏:80  手机版
解决时间 2021-02-06 12:12
  • 提问者网友:佞臣
  • 2021-02-06 09:16
C++的std:thread是怎么进行参数传递的
最佳答案
  • 五星知识达人网友:一把行者刀
  • 2021-02-06 09:22
thread 是模板,参数的形式是所谓的 forwarding reference(或 universal reference),所以传参给 thread 的构造函数时,如果参数是左值,则参数被 copy 到内部,如果传的参数是右值,则 move,无论如何 thread 内部都(暂时)保留了参数的一个 copy,然后内部传给用户的函数时,直接 move.
全部回答
  • 1楼网友:思契十里
  • 2021-02-06 10:30
std::thread(调用的线程函数,) 最基本简单的, 例子: #include  #include  using namespace std; void threadtest() { cout << "little thread" << endl; } int _tmain(int argc, _tchar* argv[]) { std::thread t1(threadtest); t1.join(); return 0; }朋友,请【采纳答案】,您的采纳是我答题的动力,如果没有明白,请追问。谢谢。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯