c++ linked list not working
<p>I am trying to make a linked list but am running into problems because I am deleting my nodes twice. The problem only arises when a node is passed into a function (if it is passed by reference everything is fine) which leads me to believe that the object being passed into the function is being copied in such a way that the pointers are pointing to nodes from the original list not the new list. I tried to get around this by overloading the = operator but this didn't work either. An explanation of what I'm doing wrong would be great.</p>

<p>Thanks for the help</p>

<pre><code>#include &lt;iostream&gt;

struct node{
    node(int n){
        if (n == 1){
            data = 1;
            next = NULL;
        }
        if (n == 2){
            data = 2;
            next = new node(1);
            next -&gt; next = NULL;
        }
    }
    ~node(){
        std::cout &lt;&lt; data &lt;&lt; std::endl;
        if (next != NULL) delete next;
    }

    void operator=(node a){
        next = NULL;
    }

    int data;
    node* next;
};

void func2(node v){
}


int main(){

    node v(2);
    if (v.next -&gt; next == NULL) std::cout &lt;&lt; "true\n";
    func2(v);

    return 0;
}
</code></pre>