G
Glen Able
Without further ado, here's some code:
std::list<int> things;
things.push_back(1);
things.push_back(2);
things.push_back(3);
std::list<int>::iterator it;
int test;
it = things.end();
test = *it; // obviously garbage
things.push_back(4);
test = *it; // garbage - but I was expecting '4'
I assumed that 'list' maintained an extra empty node at the end, which is
what gets returned by list.end(). Then I'd expect the 'push_back(4)' to
actually attach the value 4 to that node, which should then be returned in
the second 'test = *it' statement.
Anyone care to enlighten me?
thanks,
G.A.
std::list<int> things;
things.push_back(1);
things.push_back(2);
things.push_back(3);
std::list<int>::iterator it;
int test;
it = things.end();
test = *it; // obviously garbage
things.push_back(4);
test = *it; // garbage - but I was expecting '4'
I assumed that 'list' maintained an extra empty node at the end, which is
what gets returned by list.end(). Then I'd expect the 'push_back(4)' to
actually attach the value 4 to that node, which should then be returned in
the second 'test = *it' statement.
Anyone care to enlighten me?
thanks,
G.A.