-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&)'
請創建一個[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)向我們展示。 「朋友」聲明何時何地? –