我有
template < typename threadFuncParamT >
class ThreadWrapper
{
public:
static int ThreadRoutineFunction(void* pParam);
int ExecuteThread();
ThreadWrapper(ThreadPool<threadFuncParamT> *pPool);
};
template<typename threadFuncParamT>
int ThreadWrapper<threadFuncParamT>::ThreadRoutineFunction(void* pParam)
{
ThreadWrapper<threadFuncParamT> *pWrapper = reinterpret_cast<ThreadWrapper<threadFuncParamT>*>(pParam);
if(pWrapper != NULL)
{
return pWrapper-ExecuteThread(); // Error here.
}
return 0;
}
template < typename threadFuncParamT >
ThreadWrapper<threadFuncParamT>::ThreadWrapper(ThreadPool<threadFuncParamT> *pPool)
{
ThreadWrapper<threadFuncParamT>::m_pThreadPool = pPool;
m_tbbThread = new tbb::tbb_thread(&(ThreadWrapper<threadFuncParamT>::ThreadRoutineFunction), this);
if (m_tbbThread->native_handle() == 0)
{
delete m_tbbThread;
m_tbbThread = NULL;
// TODO: throw execption here or raise assert.
}
}
我收到如下错误 错误1 error C2352: 'ThreadWrapper::ExecuteThread' : 非法调用非静态成员函数
我在 VS2010 上编译。
谁能帮我解决这个错误。
谢谢!
最佳答案
问题是你的错误行
return pWrapper-ExecuteThread(); // Error here.
遗漏了一个>
;应该是
return pWrapper->ExecuteThread(); // Error here.
你得到了这样一个奇怪的编译错误,因为它试图执行减法;指针 pWrapper
被视为整数,并从中减去通过调用 ExecuteThread()
(产生 int
)返回的值。但是,ExecuteThread()
既不是全局函数也不是静态成员函数 - 因此编译器会报错。
关于使用模板的C++静态编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6941478/