problem with assignment operator in class declaration file/implementation

hello, i am trying to create the assignment operator for a class that uses a pointer for it's private variable. The error is saying expected constructor, deconstructor, or type conversion before "operator. (which is the assignment operator. I have tried everything i could think of or find online and nothing has worked. below is the code for the assignment operator in the .h file and the .cpp file. If anybody can help i would greatly appreciate it thank you.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29


 //Assignment constructor
   indexList &operator=(const indexList <T> &rhs);



template <class T>
indexList<T>::indexList operator=(const indexList <T> &rhs)
{
  if(this != &rhs)
    {
      numberOfElements = rhs.numberOfElements;
        maxSize = rhs.maxSize;
      delete list;
      list = new T[maxSize];
      for(int i=0; i < maxSize; i++)
        {
          list[i] = rhs.list[i];
        }
    }
  return *this;
}





1
2
template<class T>
indexList<T>& indexList<T>::operator=(const indexList<T> &rhs)


Also, if you allocate with new[] you must deallocate with delete[]
Topic archived. No new replies allowed.