我正在寫一些庫,它組織和跟蹤一些任務。每當調用一個nwe任務時,我的庫文件會使用構造函數中指定的函數指針。但是,當我嘗試調用它,我得到的錯誤Symbol not found
C++ - 函數指針對象似乎不存在
在頭文件我宣佈它爲:
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!
}
(在'TaskHander(TaskID,this)'前面刪除TaskManager<T>::
;''沒有幫助。)
但它找不到符號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
]
(我不得不把這種所以翻譯可能不是acurate的!)
這也可能是有趣:
template <class T>
TaskManager<T>::TaskManager(wstring title, wstring subtitle, void (*taskHandler)(T, TaskManager<T>*)) :
// Some intatiations
{
TaskHandler = taskHandler;
// More contructor stuff
}
如何我能解決這個問題嗎?
什麼是錯誤? –
也許是因爲你聲明它是一個非靜態的私有變量? – BrainSteel
我在非靜態成員函數中調用它。稱它不應該是一個問題。錯誤是,如上所述,編譯器找不到符號'TaskHandler' – BrainStone