使用模板和可变参数模板进行线程初始化

时间:2015-12-27 20:43:45

标签: c++ multithreading templates

我需要使用模板初始化std::thread

class Loader
{
    template <class T, class ...TArgs>
    static void work(T t, TArgs ...args)
    {
        //do stuff
    }
    template <class T, class ...TArgs>
    static void Load(T t, TArgs ...args)
    {

        thread thr = thread(Loader::work,t,args...);
        thr.join()
    }
}

我把它绑在我的自定义类初始化上并且工作正常,但我不知道我应该如何处理线程。

感谢您的任何建议

1 个答案:

答案 0 :(得分:2)

您需要明确指定模板中使用的类型:

thread thr = thread(Loader::work<T, TArgs...>,t,args...);
相关问题