2017-09-03 44 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'を使用するには' 'を含めます。その後、これは再現可能な問題ではありません。 – StoryTeller

答えて

0

あなたはword_frequencyという名前の関数を定義していない、また、あなたが定義されているヘッダを含めませんでした。したがって、関数はリンカーには分かりません。