title: Change an object passed by pointer to a function
body: <p>I need:</p>
  
  <ol>
  <li><p>Create reference to object.</p></li>
  <li><p>Pass it to a function that calls the constructor of the object's class and make some calculation over the object.</p></li>
  <li><p>Pass the object to another function that also make some stuff with it.</p></li>
  </ol>
  
  <p>My object that goes to the second function is always empty. </p>
  
  <p>I slightly know the difference between stack and heap memory and the use of new operator but can't handle with it. I don't understand why <code>g</code> doesn't change after the func1 is over.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class Grid
  {
      public:
          int a;
  
          Grid()
          {
              a = 2;
          }
  };
  
  void func1(Grid * g);
  void func2(Grid * g);
  
  int
  main ()
  {
      Grid g;
      func1(&amp;g);
      func2(&amp;g);
  }
  
  void
  func1 (Grid * g)
  {
      g = new Grid();
      g-&gt;a = 5;
  }
  
  void
  func2 (Grid * g)
  {
      std::cout &lt;&lt; g-&gt;a &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>How make the output in the func2 5, cause now it's 2?</p>