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.
The relevant code is below.
Promise<std::vector<std::reference_wrapper<Detection>>> HuntRegister::RunHunt(IN Hunt& hunt,
IN CONST Scope& scope OPTIONAL){
return ThreadPool::GetInstance().RequestPromise<std::vector<std::reference_wrapper<Detection>>>(
[hunt, scope]() mutable {
return hunt.RunHunt(scope);
});
The RequestPromise function just defers a function call until it can be executed later without modifying any part of it.
When I break before the return and look at hunt
, this is what I see.
When I break inside the lambda and look at hunt
, the v-table has changed.
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?