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