I am new to C++ and I'm trying to understand how this piece of code works.
~List() {
for(auto& i : nodes) {
delete &i;
}
}
I have made a Simple Linked List class that has a vector of nodes.
What I am trying to understand is, if I delete the current node, how does the for each loop know where the next node is?
How I thought it would work is, I would store a pointer to the next node and delete the current one, and repeat this process until the next node is nullptr.
(Maybe my understanding of vectors is not complete or I don't understand how for-each loops work.)
Can someone who understands how this code works please explain what is going on here?