AggrorJorn Posted March 31, 2013 Posted March 31, 2013 I am iterating through a list of LE3 Models. I had some trouble getting the position of every object during an iteration. I finnaly found something that works, but it looks really nasty. There must be a different way of accessing LE3 commands but I haven't found another way. list<Model*>::iterator it; for(it=roadBlocks.begin(); it != roadBlocks.end(); ++it) { it._Ptr->_Myval->GetPosition() Also when I debug, this is how it looks: Quote
Rick Posted March 31, 2013 Posted March 31, 2013 I usually do the following with the iter (*iter)->GetPosition(), but not sure if that works with Leadwerks 3. Haven't tried. 1 Quote
AggrorJorn Posted March 31, 2013 Author Posted March 31, 2013 Ah the parentheses around the *iter are necessary. I hadn't tried one. thanks for the help Rick. Quote
Rick Posted March 31, 2013 Posted March 31, 2013 If I need to do a bunch of things to the pointer in the loop I'll do: Model* mdl = (*iter); at the top of the loop so I can just work with mdl-> instead of (*iter)-> which is just easier. 1 Quote
AggrorJorn Posted March 31, 2013 Author Posted March 31, 2013 Thanks for the suggestion. Still have a question about this: if we put '*' before the variable, don't we de-reference it? Why can we still access functions then via the -> notation? Quote
Josh Posted March 31, 2013 Posted March 31, 2013 It's a pointer, so it's the same object. I usually do this: list<Entity*>::iterator entity; for (entity = entities.begin(); entity != entities.end(); entity++) { Vec3 position = (*entity)->GetPosition(); } Quote Let's build cool stuff and have fun.
Furbolg Posted March 31, 2013 Posted March 31, 2013 The problem is if you write " *it->MyMethod() " (example to show the problem) then c++ will try to use " * " (asterisk) on MyMethod but you want it on " it ", so you have to write (*it) to deferencing the iterator. // Edit: to clarify you could write something like this Mycallback = &(*it)->GetMethodToCallBack(); Quote
Rick Posted March 31, 2013 Posted March 31, 2013 @Aggror Like Furblog says, you aren't deferencing the actual type by doing that, but the iterator itself. Once you do that then you have a pointer of the type you actually care about. Quote
AggrorJorn Posted March 31, 2013 Author Posted March 31, 2013 De-referencing a pointer can result in to another pointer. I didn't know that. Thanks everyone. Learned something new here. Quote
shadmar Posted March 31, 2013 Posted March 31, 2013 I did not get() *it, but good::point Quote HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.