jeudi 5 avril 2018

memory leak delete linked list node

Newbie question. Suppose I have a C++11 linked list implementation with

template <typename X> struct Node {
   X value;
   Node* next;

   Node(X x) {
      this->value = x;
      this->next = nullptr;
   }
};

and later in the code I create a pointer variable

X x = something;
Node<X>* node = new Node(x);

and still later I do

delete node;

Is the x stored within node destructed when this statement is executed?

You may tell me I should use std::list instead of writing my own, but right now I'm just trying to educate myself on pointers.

Aucun commentaire:

Enregistrer un commentaire