How can I get the penultimate element in a list?

Viewed 3477

I have a std::list<double> foo;

I'm using

if (foo.size() >= 2){
    double penultimate = *(--foo.rbegin());
}

but this always gives me an arbitrary value of penultimate.

What am I doing wrong?

3 Answers
Related