how to delete myself with reference
<pre><code>void deleteElement(LinkedListElement&lt;char&gt; *&amp;pending)
{
    if (pending-&gt;Next) {
        char value = pending-&gt;Next-&gt;Data;
        pending-&gt;Data = value;
        LinkedListElement&lt;char&gt; *temp = pending-&gt;Next;
        pending-&gt;Next = pending-&gt;Next-&gt;Next;
        delete temp;
    }else{
        pending = NULL;
        //pending =nullptr;
        delete pending;
    }
}
</code></pre>

<p>Simple delete node in C++
what i want to ask is in the else statement, if the linked list is end , so i can just delete myselft, i pass value by reference(&amp;), but it does not work </p>

<pre><code>void deleteElement(LinkedListElement&lt;char&gt; *&amp;pending)
{
    if (pending-&gt;Next) {
        char value = pending-&gt;Next-&gt;Data;
        pending-&gt;Data = value;
        LinkedListElement&lt;char&gt; *temp = pending-&gt;Next;
        pending-&gt;Next = pending-&gt;Next-&gt;Next;
        delete temp;
    }else{
        delete pending;
        //pending = NULL;
    }
}
</code></pre>

<p>i try this way, but it always give me error:
malloc: <strong>* error for object 0x100103b40: pointer being freed was not allocated
*</strong> set a breakpoint in malloc_error_break to debug</p>
