title: Issue when implementing a Node class
body: <p>Can someone please tell me what is wrong with the following code ? I am trying to implement
  a graph with a class Node which contains the node id and a vector of pointer to its neighbors. Here is a short version of my code :</p>
  
  <pre><code>#include&lt;vector&gt;
  #include&lt;iostream&gt;
  
  using namespace std;
  
  
  class N {
  public:
      int i;
      vector&lt;N*&gt; v;
      N(int i) {
          this-&gt;i = i;
      };
  };
  
  int init(N* n1) {
      N n2(2);
      cout &lt;&lt; "pointer " &lt;&lt; &amp;n2 &lt;&lt; endl;
      n1-&gt;v.push_back(&amp;n2);
  };
  
  int main() {
      N n1(1);
      init(&amp;n1);
      cout &lt;&lt; n1.i &lt;&lt; endl;
      cout &lt;&lt; "pointer " &lt;&lt; n1.v[0] &lt;&lt; endl;
      cout &lt;&lt; n1.v.at(0)-&gt;i &lt;&lt; endl;
      return 0;
  };
  </code></pre>
  
  <p>The problem is that after the call to the init function, it seems that the node n2 does not exist anymore. </p>
  
  <p>Thanks for your help.</p>