<vector> problem

Started by
3 comments, last by Mage2k 21 years, 2 months ago
Ok. Here''s the problem: I am writing an inheritance hiearchy for scene graph nodes. I am using s to hold a node''s children list. For some reason I cannot add more than one item to any given . Here''s what happens: after I add one element (Node*) to a the First and Last iterator''s should both point to the same (the only) element, correct? Unfortunately, when debugging (in vc++ 6.0) I see that the First iterator is set to point to the element, but not the Last iterator which doesn''t point to anything. This obviously causes a problem with adding more elements, which then results in whole branches of a scene graph not being processed/drawn. I have repeated this behavior with someone else''s code so I know it''s not me. (Yes, I have asked the person who wrote the other code, but have not heard back from them.) Any ideas on what is going on?
---------------------------------------------------There are 10 kinds of people in the world:Those that understand binary, and those that dont...Mage
Advertisement
First of all, you can't use < and > in your text like that; enclosed text is interpreted as tags and rendered invisible.

For the question itself: What do you mean by 'First' and 'Last'? The vector class has two functions that return iterators, called begin() and end() - begin() returns an iterator to the first element, while end() returns an iterator which points one element beyond the last element (so that the last element is end()-1). There are also the functions front() and back(), returning (constant) references to the first and last elements, respectively.

This, of course, is all in the MSDN docs that ship with VC++.

[edited by - Miserable on February 7, 2003 6:10:44 PM]
Don''t use VC++6''s STL; it''s buggy and slow. Download STLPort.
hehe... sorry about the s... wasn''t thinking... as far as First and Last go, the watch window in vc++ list''s my vectors as having members: alloc, _First, _Last, and _End which equate to the relevant pointers (which iterators essentaially are) into the vector, i.e they point to what would be returned by front() and back() and end().
---------------------------------------------------There are 10 kinds of people in the world:Those that understand binary, and those that dont...Mage
crap... did it again... sorry
---------------------------------------------------There are 10 kinds of people in the world:Those that understand binary, and those that dont...Mage

This topic is closed to new replies.

Advertisement