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':使用類模板需要模板參數列表
我收到一個鏈接錯誤:未解決的錯誤:錯誤錯誤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
@icecrime我剛剛做了,但我得到了同樣的錯誤。 – 2010-11-21 21:58:01
@cable:你是否試圖在不同的文件中分別聲明和定義?這不適用於模板。 – fredoverflow 2010-11-21 21:58:16