c ++ variadic模板导致std :: tuple错误c2661

时间:2017-02-15 08:51:44

标签: c++ templates pointers variadic

写这个会产生编译错误,我该如何解决?

ThreadManager<MyWidget> u(&MyWidget::ss, this, false);
u.Invoke();

严重级代码描述项目文件行抑制状态 错误C2661&#39; std::tuple<void (__cdecl MyWidget::* )(void),MyWidget>::tuple&#39;:没有重载函数需要2个参数

但是编译得很好

ThreadManager<MyWidget> u(&MyWidget::ss, this, false);
//u.Invoke();

这是代码

#pragma once
#include <thread>

class __declspec(dllexport) ThreadBase
{};

template<class T, class... ARG>
class __declspec(dllexport) ThreadManager : public ThreadBase
{
    typedef void(T::*_func)(ARG...);

    std::thread m_thread;

    _func m_Func;
    const bool arged;
    T* m_Obj;

public:

    ThreadManager(_func f, T* obj, bool arged);

    void Invoke(ARG&&... args);

    ~ThreadManager();
};


template<class T,class... ARG>
void  ThreadManager<T, ARG...>::Invoke(ARG&&... args)
{
    if (!arged)
        m_thread = std::thread(m_Func, *m_Obj);
    else
        m_thread = std::thread(m_Func, *m_Obj, std::forward<ARG>(args)...);

    m_thread.detach();
}

template<class T,class... ARG>
ThreadManager<T,ARG...>::ThreadManager(_func f, T* obj, bool arged) : arged(arged), m_Obj(obj), m_Func(f)
{}


template<class T,class... ARG>
ThreadManager<T,ARG...>::~ThreadManager()
{
    m_thread.join();
}

0 个答案:

没有答案