Copy Function changing value?

This is a discussion on Copy Function changing value? within the C++ Programming forums, part of the General Programming Boards category; Ok the result of my copy function is weird. For people going to look at it. I am using an ...

1. Copy Function changing value?

Ok the result of my copy function is weird. For people going to look at it. I am using an array of records where everything stored is in the same array. So if i put in 3 and 2 as one set then 4 and 7 as one set has

location: 0 | .info 3 | .next NUL
location: 1 | .info 2 | .next 0
location: 2 | .info 4 | .next NUL
location: 3 | .info 7 | .next 2

If i were to print out the original list BEFORE i exit the copy function it prints it fine and everything is correct.

EDITED FROM ORIGINAL POST:
It is also weird that I pass the original list in as a constant so it SHOULD not be allowed to changed
END EDITED FROM ORIGINAL POST:

However if I print it in my driver it prints ONLY the first term wrong

Exampe:
Enter a polynomial function in the form of: "2x^2 + 3x^2" ==> 4x^5 - 3 + 3x^5

The original fucntion in copy function: 4x^5 - 3 + 3x^5
(now in driver
The original function is: 1075464688 - 3 + 3x^5
The term with the highest highest degree is: 4x5
and the degree is: 5
The derivative is: 20x^40 + 15x^4

I have no clue why this is happening. I traced my program, when I print the location where the index is printing in the driver the index is correct and is 0. So it is not pointing to the wrong index. FOr some reason my .info changes when I try and print it inside my driver but in my copy function it is not changed.

I know this question may be hard for you guys to answer but if I can recieve ANY help i be grateful.

GetIndex() returns the location of the first item (basically where NUL is
and
GetListData(): Returns the location of the last item
so location 1 for the original list and location 2 for the new

GetNode(location2, storage);
finds the next free node in storage and puts it value into location2

Code:
```void Polynomial::operator=(const Polynomial old)
{
int location = old.GetIndex();
int location2 = 999; // weird
Terms toCopy;

for (int i = location; i <= old.GetListData(); i++)
{
// makes a node, index=locatio2
GetNode(location2, storage);

if (i == old.GetIndex())
SetIndex(location2);

toCopy = storage.nodes[i].info;
storage.nodes[location2].info = toCopy;
storage.nodes[location2].next = listData;
listData = location2;
}
}```

2. My guess is Terms does not copy right. May I see code for Terms?

3. My experience has been that when I get weird output like that I have forgotten to initialize/assign a value to a variable. Seeing more code, with appropriate comments, would help those willing to help you try to track it down.