0

我正在编写某种可以组织和跟踪某些任务的库。每当调用 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
}

我怎么能解决这个问题?

4

2 回答 2

0

这是一个错字。我拼写了,TaskHander但它是TaskHandler(我忘记了l

无论如何谢谢你!

于 2013-07-03T16:29:29.477 回答
0

如果它是一个普通成员,它是一个函数指针(这似乎是你的类声明中的内容),你应该这样称呼它:

template <class T>
void TaskManager<T>::startActualTask()
{
    TaskHandler(TaskID, this);
}

您只对静态成员或 typedef使用TaskManager<T>::前缀。

于 2013-07-03T16:22:22.087 回答