Hello,
I am working on a template vector class. I have to have both a .h and .cpp file for this (already emailed teacher saying I that many people just put the implementation of template classes all in the same .h file). Anyway, I am running into an issue with overloading the operator =.
MyVector.h
MyVector.cppCode:MyVector& operator=(const MyVector &rhs);
The error I am getting is:Code:emplate <typename T> MyVector& MyVector<T>::operator=(const MyVector &rhs) { // Code here }
I've not done much template work, so I am not sure what exactly this is getting at. Thanks for any help.Code:error: invalid use of template-name ‘MyVector’ without an argument list
Edit:
If in the .cpp I change it to:
Everything seems to work. Can someone explain this to me? Is this the right approach? I assume I need to specify the template type at each stage to indicate that this particular use of the = operator is of type T.Code:template <typename T> MyVector<T>& MyVector<T>::operator=(const MyVector<T> &rhs) { // Code here }
Thanks!




Reply With Quote