我想通過一個函數作爲參數在C++中。我不斷收到一個LNK2019無法解析的外部符號錯誤。錯誤LNK2019「無法解析的外部符號」,當傳遞一個函數作爲參數
我已閱讀過這些內容,並已修復過這些內容,但我無法弄清楚我在這裏做錯了什麼。
main.ccp
的錯誤似乎與我的顯示功能中我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 }
}
調試注意事項:
我試圖在主要使用這種類型的,並沒有收到任何錯誤。另外,無論我是否註釋掉該函數的用法,它是否出錯。所以它似乎是我的函數定義的問題,而不是它的用法。
任何幫助表示讚賞。提前致謝!
請包括您收到的** complete **錯誤。你已經省略了告訴你的部分*什麼符號是未解決的* –
對不起,也許我應該更具描述性。我試圖讓事情儘可能簡單。現在解決了,謝謝。 – SomeRandomDeveloper