C++ 使用模板和可变模板进行线程初始化
我需要使用模板初始化C++ 使用模板和可变模板进行线程初始化,c++,multithreading,templates,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) {
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()
}
}
类加载器
{
模板
静态无效功(T、T、TArgs…args)
{
//做事
}
模板
静态空隙荷载(T、TArgs…args)
{
线程thr=线程(加载器::work,t,args;
thr.join()
}
}
我把它绑定在自定义类初始化上,它已经工作了,但我不知道该如何处理线程
感谢您的建议您需要明确指定模板中使用的类型:
thread thr = thread(Loader::work<T, TArgs...>,t,args...);
thread thr=线程(加载器::work,t,args;