Reputation: 3493
ok, so here's my header file (or at least part of it):
template<class T>
class List
{
public:
.
:
List& operator= (const List& other);
.
:
private:
.
:
};
and here is my .cc file:
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;
}
on the line List& List<T>::operator= (const List& other)
I get the compilation error "Expected constructor, destructor, or type conversion before '&' token". What am I doing wrong here?
Upvotes: 1
Views: 321
Reputation: 53289
The return type List&
can't be used without the template arguments. It needs to be List<T>&
.
template <class T>
List<T>& List<T>::operator= (const List& other)
{
...
}
But note that even after you fix this syntax error, you'll have linker problems because template function definitions need to be placed in the header file. See Why can templates only be implemented in the header file? for more information.
Upvotes: 3