dimanche 5 décembre 2021

values are changing inside lambda when values are passed via capture list [closed]

I have a peculiar problem, I am unable to reproduces issue outside the project and since I cannot share the original code, Here I am sharing a pseudo code of that

void foo(
    const std::vector<uint8_t>& randomNr,
    const std::vector<uint8_t>& lists,
    const int32_t id)
{
    // value of id here is as expected 
    auto fut = someotherAsynCall(
        lists,
        randomNr,
        [&, this](ReqResult reqResult) {
            // value of id here is as different and not as expected
        });

    if (fut.valid()) {
        fut.get();
    }
}

Forget about function calls and other parameter only thing is why id value is printing different value once it goes inside lambda callback

Aucun commentaire:

Enregistrer un commentaire