我正在编写某种可以组织和跟踪某些任务的库。每当调用 nwe 任务时,我的库都会使用构造函数中给出的函数指针。但是当我尝试调用它时,我得到了错误Symbol not found
在头文件中,我将其声明为:
template <class T>
class TaskManager
{
private:
// other variables
T TaskID; // This is defined like this (just to clear things up)
void (*TaskHandler)(T, TaskManager<T>*);
// some more stuff
};
我称之为
template <class T>
void TaskManager<T>::startActualTask()
{
(*TaskManager<T>::TaskHander)(TaskID, this); // Errors!
}
或者
template <class T>
void TaskManager<T>::startActualTask()
{
TaskManager<T>::TaskHander(TaskID, this); // Errors!
}
(TaskManager<T>::
在 'TaskHander(TaskID, this);' 前面删除没有帮助。)
但它找不到符号TaskHandler
。不管我到目前为止尝试了什么!
完整的错误是:
e:\eigene dateien\visual studio 2010\projects\brainstonemod - publish\brainstonemod - publish\TaskManager.cpp(212): error C2039: 'TaskHander': Is no element of 'TaskManager<T>'
with
[
T=int
]
e:\eigene dateien\visual studio 2010\projects\brainstonemod - publish\brainstonemod - publish\TaskManager.cpp(211): At the compiling of the class template of the void TaskManager<T>::startActualTask(void) member function
with
[
T=int
]
e:\eigene dateien\visual studio 2010\projects\brainstonemod - publish\brainstonemod - publish\TaskManager.cpp(73): At the compiling of the class template of the void TaskManager<T>::addTask(Task<T>) member function
with
[
T=int
]
e:\eigene dateien\visual studio 2010\projects\brainstonemod - publish\brainstonemod - publish\TaskManager.cpp(9): At the compiling of the class template of the TaskManager<T>::TaskManager(std::wstring,std::wstring,void (__cdecl *)(T,TaskManager<T> *)) member function
with
[
T=int
]
main.cpp(14): See the Instatiation of the just compiled class template "TaskManager<T>".
with
[
T=int
]
(我必须翻译这个。所以它可能翻译不准确!)
这也可能很有趣:
template <class T>
TaskManager<T>::TaskManager(wstring title, wstring subtitle, void (*taskHandler)(T, TaskManager<T>*)) :
// Some intatiations
{
TaskHandler = taskHandler;
// More contructor stuff
}
我怎么能解决这个问题?