title: Lambda capture by value messing up v-table
body: <p>I am writing a function that creates a lambda that will later be used to call a function. This lambda captures a local variable by value, and it appears to be modifying the v-table as this happens.</p>
  <p>The relevant code is below.</p>
  <pre><code>Promise&lt;std::vector&lt;std::reference_wrapper&lt;Detection&gt;&gt;&gt; HuntRegister::RunHunt(IN Hunt&amp; hunt, 
                                                                                IN CONST Scope&amp; scope OPTIONAL){
  
      return ThreadPool::GetInstance().RequestPromise&lt;std::vector&lt;std::reference_wrapper&lt;Detection&gt;&gt;&gt;(
          [hunt, scope]() mutable { 
              return hunt.RunHunt(scope); 
          });
  </code></pre>
  <p>The RequestPromise function just defers a function call until it can be executed later without modifying any part of it.</p>
  <p>When I break before the return and look at <code>hunt</code>, this is what I see.
  <a href="https://i.stack.imgur.com/BiAHz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BiAHz.png" alt="Before capture by value" /></a></p>
  <p>When I break inside the lambda and look at <code>hunt</code>, the v-table has changed.
  <a href="https://i.stack.imgur.com/Yv8TF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yv8TF.png" alt="After capture by value" /></a></p>
  <p>Based on the comments, it looks like the culprit here is object slicing. There's a bunch of solutions for preserving members, but I haven't found anything explaining how I can fix my issue. What can I do to ensure the v-table is preserved?</p>