title: return by value inline functions
body: <p>I'm implementing some math types and I want to optimize the operators to minimize the amount of memory created, destroyed, and copied. To demonstrate I'll show you part of my Quaternion implementation.</p>
  
  <pre><code>class Quaternion
  {
  public:
      double w,x,y,z;
  
      ...
  
      Quaternion  operator+(const Quaternion &amp;other) const;
  }
  </code></pre>
  
  <p>I want to know how the two following implementations differ from eachother. I do have a += implementation that operates in-place to where no memory is created, but some higher level operations utilizing quaternions it's useful to use + and not +=.</p>
  
  <pre><code>__forceinline Quaternion Quaternion::operator+( const Quaternion &amp;other ) const
  {
      return Quaternion(w+other.w,x+other.x,y+other.y,z+other.z);
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>__forceinline Quaternion Quaternion::operator+( const Quaternion &amp;other ) const
  {
      Quaternion q(w+other.w,x+other.x,y+other.y,z+other.z);
      return q;
  }
  </code></pre>
  
  <p>My c++ is completely self-taught so when it comes to some optimizations, I'm unsure what to do because I do not know exactly how the compiler handles these things. Also how do these mechanics translate to non-inline implementations.</p>
  
  <p>Any other criticisms of my code are welcomed.</p>