我正在尝试将函数作为 C++ 中的参数传递。我不断收到 LNK2019 未解决的外部符号错误。
我已经阅读了这些内容,并在过去修复了这些内容,但我无法弄清楚我在这里做错了什么。
主文件
该错误似乎发生在我的显示函数中的 TreeItemType 引用中。
include "PhoneBook.h"
include "PhoneEntry.h"
include "bst.h"
using namespace std;
using namespace p04NS;
void display(TreeItemType& item);
int main() {
PhoneEntry test = PhoneEntry("first", "last", "618-580-0680");
bst * tree = new bst();
TreeItemType foo = TreeItemType(); // test type reference, no error
tree->insert(test);
tree->inorder(display);
system("pause");
return 0;
}
void display(TreeItemType& item){
cout << "hello worlds!";
}
bst.h
TreeItemType typedef 在这里定义。
namespace p04NS {
typedef PhoneEntry TreeItemType;
typedef string KeyType;
// Pointer to a function that can be used to display the item.
typedef void (*FunctionType)(const TreeItemType& item);
class bst { //some codez }
}
调试说明:
我尝试在 main 中使用这种类型,并且没有收到错误。另外,无论我是否注释掉该函数的用法,它是否都会出错。所以这似乎是我的函数定义的问题,而不是它的用法。
任何帮助表示赞赏。提前致谢!