Is this legal?:
Sample& sample = stack.front();
stack.pop_front();
My program works. But Sample class have boost::optional<boost::posix_time::ptime> xxx member and after pop_front, is_initialized() returns false;
No, this is not legal. You must take a copy of the object, i.e. use
Sample sample = stack.front ()
If you are using a std::vector, the pop_front call moves the elements behind to the location and your reference points to a different element (the previously second, now first element.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With