2010-11-21 139 views
0
template <class T> 
class ListRemake 
{ 
    ... 
    friend ostream& operator << (ostream& out, const ListRemake& obj); 
}; 

template <class T> 
ostream& operator << (ostream& out, const ListRemake& obj) 
{ 
    for (int i = 0; i < obj.size; i++) 
     out << obj[i] << '\n'; 
    return out; 
} 

給出錯誤C2955:'ListRemake':使用類模板需要模板參數列表。錯誤C2955:'ListRemake':使用類模板需要模板參數列表

回答

0

更換

ostream& operator << (ostream& out, const ListRemake& obj) 

ostream& operator << (ostream& out, const ListRemake<T>& obj) 
+0

我收到一個鏈接錯誤:未解決的錯誤:錯誤錯誤LNK2019:無法解析的外部符號「class std :: basic_ostream >&__cdecl operator <<(class std :: basic_ostream >&class class ListRemake const&)「(?? 6 @ YAAAV?$ basic_ostream @ DU?$ char_traits @ D @ std @@@ std @@ AAV01 @ ABV?$ ListRemake @ N @@ @Z)函數_main中引用 – 2010-11-21 21:54:16

+0

@icecrime我剛剛做了,但我得到了同樣的錯誤。 – 2010-11-21 21:58:01

+0

@cable:你是否試圖在不同的文件中分別聲明和定義?這不適用於模板。 – fredoverflow 2010-11-21 21:58:16

0

錯誤是告訴你ListRemake是一個模板,因此你需要實例化它作爲一個類型(你在做什麼<<操作符)。

+0

我不知道我很理解。我做錯了什麼,我應該改變什麼? – 2010-11-21 22:03:12