title: In C++, Do objects get copied to the stack when I pass them to a function by value?
body: <p>I'm just starting to get into C++ (I'm an experienced Python/Java developer getting into the better parts of OpenCL) and I'm very confused by how objects are passed into functions.</p>
  
  <p>Let's say I have a simple class:</p>
  
  <pre><code>class Thing {
      int var;
      int var2;
      int var3;
  
      void doSomething();
  };
  </code></pre>
  
  <p>Now, the "size" of this class is at least <code>3*sizeof(int)</code> (I'm not sure if a function pointer is stored or not). Now say I have two function signatures:</p>
  
  <pre><code>void doThing1(Thing t);
  void doThing2(Thing* t);
  </code></pre>
  
  <p>When I call <code>doThing1</code>, does it cause the entire instance to be copied onto the stack? When I call <code>doThing2</code>, does it only require <code>sizeof(Thing*)</code> stack space?</p>
  
  <p>A lot of "conventional wisdom" out there on the Internet has been telling me to try to use the function signature of <code>doThing1</code>, but at first glance that seems very silly -- if it does indeed copy the entire object.</p>
  
  <p>I also assume that if a function is going to modify an object that's on the heap (created with the <code>new</code> keyword) it ought to look like <code>doThing1</code>.</p>
  
  <p>Please, correct my ignorance. Either my Google searches aren't being helpful or Google isn't being helpful.</p>