2017-10-09 6 views
-2
friend ostream& operator<< (ostream& os,const aList<T>&); 

template <class T> 
ostream & operator << (ostream &output,const aList<T>& a){ 
    output<<a.length; 
    return output; 
} 

................................ .....テンプレートクラスのアウトプットオペレータオーバーロードのエラーを取り除く方法

error: g++ -c -g -MMD -MP -MF "build/Debug/Cygwin-Windows/aList.o.d" -o build/Debug/Cygwin-Windows/aList.o aList.cpp 
In file included from aList.cpp:2:0: 
aList.h:22:68: warning: friend declaration ‘std::ostream& operator<<(std::ostream&, const aList<T>&)’ declares a non-template function [-Wnon-template-friend] 
      friend ostream& operator<< (ostream& os,const aList<T>&); 
                    ^
aList.h:22:68: note: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here) 
mkdir -p dist/Debug/Cygwin-Windows 
g++  -o dist/Debug/Cygwin-Windows/alist build/Debug/Cygwin-Windows/_ext/2ebfcef6/newstring.o build/Debug/Cygwin-Windows/aList.o build/Debug/Cygwin-Windows/alist1.o 
build/Debug/Cygwin-Windows/alist1.o: In function `main': 
/cygdrive/c/Users/Zunera Jamal/Documents/NetBeansProjects/aList/alist1.cpp:50: undefined reference to `operator<<(std::ostream&, aList<newstring> const&)' 
/cygdrive/c/Users/Zunera Jamal/Documents/NetBeansProjects/aList/alist1.cpp:50:(.text+0x2ca): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `operator<<(std::ostream&, aList<newstring> const&)' 
+5

私たちを表示するには[最小、完全で、検証可能な例](http://stackoverflow.com/help/mcve)を作成してください。いつ、どこで 'friend'宣言がありますか? –

答えて

0

一見すると、あなたの友人宣言がテンプレート宣言を参照しているがその外にあるという事実はあなたの最初の問題のようです。

この質問を確認してください。それは非常に関連しているようです: friend declaration declares a non-template function

関連する問題