0

我有一个带有以下方法的线程管理器类:

template <class _Fn, class... _Args>
void create_thread (_Fn&& fun, _Args&&... args)
{
    std::thread t (std::mem_fn(&MyClass::threads_entry<_Fn, _Args...>),
                    this, fun, args...);
}

template <class _Fn, class... _Args>
void threads_entry (_Fn&& fun, _Args&&... args)
{
  fun (std::forward <_Args>(args)...);
  perform_on_before_thread_exit_tasks();
}

在另一堂课中,我正在尝试使用它。这个类有以下成员:

void make_sure_thread_created ()
{
    m_threads.create_thread (
                    &MyClass2::thread_tasks,
                    this);
}

void thread_tasks ()
{
}

我收到编译错误(MS VC2013):

error: C2064: term does not evaluate to a function taking 1 arguments

它指向这行代码:

fun (std::forward <_Args>(args)...);

难道我做错了什么?或者它是编译器错误?在这里可以做什么?...

4

1 回答 1

0

这似乎是 VC2013 和 VC2015 编译器的错误。

解决方法:

m_threads.create_thread (
    std::bind (&MyClass2::thread_tasks, std::placeholders::_1),
    this);
于 2015-11-28T22:13:35.480 回答