Universal references in a thread function

后端 未结 2 1242
我寻月下人不归
我寻月下人不归 2021-01-28 03:27

I have been learning about perfect forwarding and the use of && in function templates (see this previous question of mine) and would like to know if my use of Args

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-28 03:51

    The issue is that which overload of MyThreadFunc is desired is not deducible by the compiler. There are at least two ways to fix it:

    1. Rename one of the function so that it is clearer which one you want.

    2. Use explicit template parameters:

      StartDetachedThread(MyThreadFunc, object);
      StartDetachedThread(MyThreadFunc, std::move(object2));
      

提交回复
热议问题