C++ post increment is executing before the body of a for loop?
I'm going totally crazy here. I'm using Visual Studio 2008, and I can't
help but think it has a bug in it, or otherwise I've just forgotten some
serious fundamentals.
It seems that when I remove the "initialization" (first field) of my for
loop, my "post-increment" (third field) executes prior to the body of the
loop.
std::list<VideoTranscoderStats>::iterator videoStatsIter =
mTranscoderStatisticsList.begin();
for(;videoStatsIter != mTranscoderStatisticsList.end();videoStatsIter++)
{
// do stuff
}
As I debug, I can see that I'm executing "videoStatsIter++" before "do
stuff", and also before testing the condition in the for loop.
On the other hand, if I move my initialization of videoStatsIter into the
beginning of the for loop statement, everything works fine.
"videoStatsIter++" is executed following the body of the for loop.
No comments:
Post a Comment