2017-09-03 101 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功能,也没有您在其定义的标题。因此,链接器不知道该函数。