Pointer object disappearing / losing data??

Hi guys,

I'm having a very odd problem. Particularly odd because this was working perfectly when I wrote it 2 weeks ago, but now coming back to it, it's acting very weird.

Essentially, I have an object called (Train) Platform. Platform has a function String getStation() which is supposed to return the name of the station that that Platform belongs to. For example, a3UptownRed.getStation() would return "a3". The station is provided as part of the constructor of platform.

When I'm passing Platform into a pointer, it suddenly forgets it's station and returns "DEFAULT", which is the value provided if none other exists. Here's some code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void CTrainLine::add(Platform item){
    ListNode * temp = new ListNode;
    temp->data = item;
    cout << "Now adding " << item.getStation() << endl; //This prints out "A1"
    cout << "Just added " << (temp->data).getStation() << endl; //This prints out "DEFAULT"??
    if(isEmpty()){
        head->next = temp;
        temp->next = temp;
    } 
    else {
        temp->next = head->next;   
        last->next = temp;
    }
    last = temp;
    size++; 
}


For reference, here's the listnode and the platform constructor:

1
2
3
4
 struct ListNode{
      Platform data;
      ListNode * next;
 };


1
2
3
4
5
6
7
8
Platform::Platform(string stat, string dir, string tLine){
    station = stat;
    direction = dir;
    line = tLine;
    totalWaiting = 0;
    lastQueueUsed = 0;
    train = false;  
}


And here's the way I'm calling the function:

1
2
Platform a1UptownRed("a1","up","red")
redLine.add(a1UptownRed); 


Once again, I reiterate that this was working just fine a few weeks ago. I had to fix some bugs in other parts of the program and now this stopped working. I wish I could go back to last time everything was working good - this is what I get for not using version control. Never again.


Thanks a lot guys, I really, really appreciate any input.
Topic archived. No new replies allowed.