C ++ Lambda capture messes up local variable value

I'm not sure if this is a VS 2010 issue, or I am misunderstanding something. I create a boost stream through a lambda function that should change a local variable:

    auto oCurrTime( boost::posix_time::microsec_clock::universal_time() );
    auto spRequestSequenceThread = make_unique<boost::thread>( [&oCurrTime, this]()
    {
        while ( !checkAgainstSpecificTime(oCurrTime) )
        {
            ...
        }
        :
        :
    }

Before creating the stream, oCurrTime is something like 2864273654234872634, but the value is lost in the stream, and oCurrTime is something like 487465847564875465, rendering the while loop (where the time difference is for a certain specific time) is useless.

Thank you very much for your help.

PS: The above code is part of a class function

+4
source share
2 answers

, - this . , oCurrTime - , , : &, , oCurrTime, , , , .

, oCurrTime (remove &), , - , . oCurrTime .

+3

[&oCurrTime]
oCurrTime , dangling.

.

0

All Articles