No, this is not legal. You must take a copy of the object, i.e. Use
Sample sample = stack.front ()
If you use std::vector , calling pop_front moves the elements behind the place, and your landmarks point to another element (previously the second, now the first element.)
source share