2016-04-12 7 views
-1

コード:エラーLNK2019 2013

template <typename T> 
class Graf 
{ 
vector < vector <T> > Mat; 
int n, m; 
public: 
friend istream& operator >>(istream& Read, Graf <T> &Object); // this is where I get the error 
friend ostream& operator <<(ostream& Show, Graf <T> &Object); // here too, when I try to display an object 
Graf() : Mat(MAX_NODES, vector<T>(MAX_NODES)), n(0), m(0) {} 
}; 
#include "graf_implementation.h" 

i "はcinを>> G" しようとすると、私はこれは本当に厄介なエラーが発生します。

ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class  std::basic_ostream<char,struct std::char_traits<char> > &,class Graf<int> &)" ([email protected][email protected][email protected]@[email protected]@@[email protected]@[email protected][email protected]@@@Z) referenced in function _main 
+1

[定義されていない参照/未解決の外部シンボルエラーとは何ですか?どうすれば修正できますか?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-外部記号エラー・アンド・ハウ・ド・イ・フィックス) –

答えて

0

リンカがあなたを語っているものですあなたが宣言しましたが、実装していない関数のシンボルを見つけることができません。したがって、あなたは関数を実装するのを忘れていたか、それをリンクするのを忘れていました。ちょうど宣言

friend ostream& operator <<(ostream& Show, Graf <T> &Object) 
{ 
    // your implementation here 
    return Show; 
} 

後のconstオブジェクトも出てストリーミングすることができるように、実際にパラメータとしてGraf<T> const&を取得する必要があります機能を実装をインラインで記述するのが一般的です。