2010-11-21 138 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