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