Hmm.. alright I suppose that makes sense. I was just thinking returning the pointer dereferenced would still retain the original address when I send it through the other parameter.
The main issue I am having with this program is that I loop through the linkedList until I hit a NULL node. When I check through tempSet, this works successfully.
I use a while loop iterating through: tempDelete = tempDelete->node; and when tempDelete == NULL I terminate.
However in my assignment operator, my rtList never has a NULL node! I tried figuring out why by printing out rtLists' addresses and I noticed that rtList's head node had a different address than tempSet.
However to answer my main issue, rtSide.head points to a never ending linkedList.
For example I have:
strSet tempSet;
strSet tempSet2( "a" ) <--- a string with value "a" ;
1 2 3 4
|
//main.cpp
...
tempSet = (tempSet + tempSet2);
...
|
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 30 31
|
// strSet.cpp
...
strSet& strSet::operator = (const strSet& rtSide) {
nullify();
linkedList *newList, *rtList = rtSide.head;
int count = 0;
if( rtSide.head == NULL ) {
head = NULL;
return *this;
}
cout << "rtList head address: " << rtSide.head << endl;
head = new linkedList;
newList = head;
do {
newList->node = new linkedList;
newList->value = rtList->value;
rtList = rtList->node;
cout << "rtList address: " << rtList << endl;
cout << "rtList value : " << rtList->value << endl;
if(rtList == NULL) cout << "RT LIST HAS A NULL HEAD!" << endl;
newList = newList->node;
count ++;
}while( rtList != NULL && count < 10);
cout << " Yout got here!" << endl;
delete newList;
newList = NULL;
cout << "You got here!2" << endl;
return *this;
}
|
The output for this is
TempDelete head address: 0xf810b0
rtSide head address: 0xf810f0
rtList address: 0xf81110
rtList value :
rtList address: 0xf81130
rtList value: a
rtList address: 0xf81150
rtList value:
rtList address: 0xf81170
rtList value: a
rtList address: 0xf81190
rtList value:
...
you got here!
you got here!2
|
I understand that dereferencing it has made a proper copy of that object, yet why does it's linked list go on forever? The original tempSet has a finite linked List.
EDIT: To further prove what I mean, this is what happens when I iterate through tempList:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
//strset.cpp
...
strSet strSet::operator + (const strSet& rtSide) {
...
tempDelete = tempList->head;
cout << "TempDelete head address: " << tempList->head << endl;
while(tempDelete != NULL) {
cout << "tempDelete address: " << tempDelete << endl;
cout << "tempDelete node : " << tempDelete->node << endl;
tempDelete = tempDelete->node;
}
return *tempList;
...
|
This is the output I get with tempList:
TempDelete head address: 0x8d00b0
tempDelete address: 0x8d00b0
tempDelete node : 0x8d00d0
tempDelete address: 0x8d00d0
tempDelete node : 0 |