1
好了,所以这里是我的头文件(或至少它的一部分):类模板,预计构造函数,析构函数
template<class T>
class List
{
public:
.
:
List& operator= (const List& other);
.
:
private:
.
:
};
,这里是我的.cc文件:在
template <class T>
List& List<T>::operator= (const List& other)
{
if(this != &other)
{
List_Node * n = List::copy(other.head_);
delete [] head_;
head_ = n;
}
return *this;
}
行List& List<T>::operator= (const List& other)
我收到编译错误“&'令牌'之前的预期构造函数,析构函数或类型转换。我在这里做错了什么?
模板类定义必须位于头文件中。看看这个问题的解释:http://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file – 2012-04-16 12:13:08