Hi guys.
I have a problem with my D'tor. When I implement the D'tor the I get a runtime error. If the D'tor is not implemented then the program runs just fine.
Can you compile and tell me what you think about this runtime error and how I will be able to fix it?
P.S
All of the other method works just fine. I'm adding the header files, D'tor and the main(), please tell me if you want to see something else of my code(.cpp files, etc).
I see no implementation for a destructor, so I can't begin to guess what run-time error you're getting.
Please post the exact error message you getting.
My guess is one of the following:
1) You haven't implemented the ~PassengerList destructor and are getting a linker error indicating the linker can't find the destructor.
2) Since PassengerList is a linked list, you're trying to delete Passenger instances more than once. i.e. Consider after line 50, Passenger instances are on multiple lists.
Objects are destructed in reverse order, therefore passengerList3 is destructed first. That deletes all Passenger instances. Then passengerList2 is destructed, but the Passenger instances on passengerList2 instances have already been deleted.
how come they are already been deleted if passengerlist1\2\3 are differnets lists? When I make passengerlist3 I create new points and new passengers(a passenger can be in different lists at the same time)
a passenger can be in different lists at the same time
That's highly dangerous. If you delete an object from one list you need to make sure that it is removed from the other list otherwise when you try to delete an object twice your program will crash.
It happens because you have multiple pointers pointing to same passenger instnace.
When you created passengerlist3 you did a shallow copy of next (i.e. copied the pointer. You now have two passengerlists pointing to the same memory. Destructing one passenger list works fine, but when you destruct the second passengerlist, you get a run time error because you're trying to release a passenger that has already been released.