Creating a LinkedList problem

I am trying to overload the -= operator which calls a remove_all function. The idea is when -= is used in a program of two LinkedLists that all the elements from the RHS LinkedList are removed from the LHS LinkedList

The active code is as follows:

http://pastie.org/4699743

This code works if I remove line 11.

It crashes with Access Violations otherwise, at the first attempt to remove a Node.

Can any one see why this program would work if the 'delete' call is removed on line 11, but doesn't work otherwise?
what are you doing by writing this blow line
1
2
3
 
      remove_ptr = previous_ptr->get_link();
      previous_ptr->set_link(remove_ptr->get_link());

This means, i explain you by example.
let's say
previous_ptr = 1;
Than according to your code,
remove_ptr = 1;
previous_ptr->set(1);

You are doing one thing again and again..
sorry if i am wrong..
I actually copied that part out of a Textbook so it should be correct.

The previous_ptr is a Node* that is passed to the code via the parameter.

It is saying that remove_ptr is a Node* to the Node I want removed because it takes the link from previous_ptr, i.e. the connection between Nodes.

It actually sets the pointer to an address not a value.

Then it says previous_ptr has it's link set to point at the Node after the Node I want removed. Which is line 3 there.

Also it works fine and doesn't infinite loop when I take the delete statement directly below out. What would that mean?

Thanks for your reply!
Last edited on
Topic archived. No new replies allowed.