2017-09-03 107 views
-4

我試圖使用地圖作爲函數參數並獲取未定義的引用錯誤。未定義的參考

#include<iostream> 
#include<map> 
using namespace std; 
void word_frequency(map<string,int> &doc,ifstream &file){ 
} 
int main(){ 
    map<string,int> doc1; 
    ifstream file; 
    file.open("doc1.txt"); 
    word_frequency(doc1,file); 
    file.close(); 

return 0; 
} 

錯誤:

undefined reference to `word_frequency(std::map<std::string, int, std::less<std::string>, std::allocator<std::pair<std::string const, int> > >&, std::basic_ifstream<char, std::char_traits<char> >&)' 
+2

如果問題出現在文本中,錯誤會更有幫助。我們如何猜測哪條線路導致它? – StoryTeller

+0

@StoryTeller說了什麼,並告訴我們你的編譯器命令行。 – user0042

+0

包含''使用'std :: ifstream'。之後,這不是一個可重現的問題https://ideone.com/XUpGwH – StoryTeller

回答

0

你沒有定義一個名爲word_frequency功能,也沒有您在其定義的標題。因此,鏈接器不知道該函數。