title: Should I check for NULL in my assignment operator?
body: <p>I have a class</p>
  
  <pre><code>class Node {
  
    public:
      int value;
      Node * next;
  
      Node();
      Node(const Node&amp; other);
      Node&amp; operator= (const Node&amp; other);
  };
  </code></pre>
  
  <p>It's not very useful, but it has an overridden assignment operator. Everything in there is <code>public</code> because I am such an open and cooperative guy.</p>
  
  <p>Now elsewhere I have an array of these nodes:</p>
  
  <pre><code>Node * nodes = new Node[15];
  </code></pre>
  
  <p>When I try to assign a node to my array of nodes:</p>
  
  <pre><code>nodes[0] = Node();
  </code></pre>
  
  <p>I get a huge ugly crash.</p>
  
  <p>My assignment operator looks like this:</p>
  
  <pre><code>Node&amp; Node::operator= (const Node&amp; other) {
  
    // watch out for self assignment
    if (this == &amp;other) return *this;
  
    delete this-&gt;next;
    this-&gt;next = new Node(*(other.next)); // call the copy constructor
    this-&gt;value = other.value;
  
    return *this;
  }
  </code></pre>
  
  <p>I get the feeling that I should be checking for whether or not <code>this</code> is <code>NULL</code> before I go about trying to dereference its members. Any thoughts on what might be wrong?</p>