【发布时间】:2018-06-04 15:25:04
【问题描述】:
我有一个问题,给定这个 sn-p 的代码:
class Thread{
private:
template<class t_Funtion, class ... t_Args>
struct ThreadExiter
{
using CallbackType = decltype(std::bind(std::declval<t_Funtion>(), std::declval<t_Args>()...));
static CallbackType m_Callback;
template<class ... t_ConstructorArgs>
ThreadExiter(t_Funtion p_Function, t_ConstructorArgs ... p_Args) :
m_Callback(std::forward<t_Funtion>(p_Function), std::forward<t_ConstructorArgs&&>(p_Args) ...)
{
// Nothing to do
}
~ThreadExiter()
{
m_Callback();
}
};
如何实例化静态成员static CallbackType m_Callback;?
我试过了:
template<class t_Funtion, class ... t_Args>
typename Thread::ThreadExiter<t_Funtion, t_Args...>::CallbackType Thread::ThreadExiter<t_Funtion, t_Args...>::m_Callback
但我得到了:
error: no matching function for call to 'std::_Bind<int (*(Thread*)) Thread*)>::_Bind()' typename Thread::ThreadExiter<t_Funtion, t_Args...>::CallbackType Thread::ThreadExiter<t_Funtion, t_Args...>::m_Callback;
^
【问题讨论】:
标签: c++ c++11 templates stdbind