Overloading operator= in a class

Write your question here.
I am trying to write a test program to overload the operator= in a class
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
  This is the definition of the member function: 
const cAssignmentOprOverload& cAssignmentOprOverload::operator=
                      (const cAssignmentOprOverload& otherList)
{
      if(this != &otherList)    //avoid self-assognment
     {
         if(list != NULL)
             destroyList ();
          maxSize = otherList.maxSize;
          length = otherList.length;

          if(maxSize != 0)
          {
               list = new int[maxSize];
               assert(list != NULL);

               for(int i = 0; i < length; i++)
                   list[i] = otherList.list[i];
          }
          else
                   list = NULL;
          }
          return *this;
      }
 //Please help with writing the test program for this member function.    

I believe the memory allocated to list first needs to be deleted, before you execute line 14.

Correct me if im wrong.
This is an example code from DS Malik (Data structures).
All that needs to be done is to write the test program.
I eventually managed to write the test program to overload the operator=
The main program runs very well without changing anything i the definition of the
function to overload the assignment operator=

Thank you very much Arslan.
Topic archived. No new replies allowed.