Hi everybody
I really have a problem with calling the destructor
Yes, the destructor ruins everything
to get you in my problem
I'm working with lists of students
also I'm implementing a function that takes two lists and returns the
merged list of both of the previous lists.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
SortedType mergeLists(SortedType& list1, SortedType& list2){
SortedType mList;
list1.ResetList();
list2.ResetList();
Student tempS;
for(int i = 0; i < list1.LengthIs(); i++){
list1.GetNextItem(tempS);
mList.InsertItem(tempS);
}
for(i = 0; i < list2.LengthIs(); i++){
list2.GetNextItem(tempS);
mList.InsertItem(tempS);
}
//The destructor is called before this statement
return mList;
}
|
The problem is that at the end of the function before the return statement
the destructor is called and it destroys the list that has the elements from
the previous two lists. This list was created inside the same function.
basiclly the function receives references to two Student Sorted lists, merge these lists and return the merged sorted list.
Could you please give me hand how to avoid calling the destructor, or how
to return the mereged list with being destroyed.
Thnx