# STL lists and referencing

This topic is 4728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I have an STL list which holds references to a list of entities which are dynamic in my program. I am using an iterator to go through this list of items. I am trying to do the following which doesn't seem to be working
	std::list<Entity *>::iterator itor = this->m_EntitiesList.begin();
while(itor != this->m_EntitiesList.end())
{
glPushMatrix();
if((*itor)->m_bIsPlayer)
{
vector3 view = m_pCamera->GetTarget();
(*itor)->SetPosition(view.x, 0.0f, view.y);
}

(*itor)->Render();
glPopMatrix();

++itor;
}


However when I call (*itor)->SetPosition it looks like instead of referencing its doing a copy so its not affecting the value at all. I suppose that its supposed to work that way. However I would like to know how to make the SetPosition to work. Thanks

##### Share on other sites
Quote:
 Original post by CRACK123when I call (*itor)->SetPosition it looks like instead of referencing its doing a copy so its not affecting the value at all.

No, that isn't how the STL containers (or C++ in general) work. Your problem is elsewhere.

##### Share on other sites
From what I can tell, that code should be fine.

Perhaps there is something wrong with your SetPosition function?

Finally, you know you don't need to go "this->", right?

##### Share on other sites
Quote:
 Original post by Andrew RussellFinally, you know you don't need to go "this->", right?

Yes I know, I do that cos it populates the member variables and functions in vc++ so it makes it easier than going through header files when I forget the exact member variables names that are declared.

##### Share on other sites
I think there's a hotkey that does that... (anyone know what it is?)

##### Share on other sites
Oh my - actually the SetPosition call itself is wrong. I am sending in view.y instead of view.z. Well now I am sending in info correctly - it works.

I was wondering the same thing - it should have worked the way I was doing it the first time.

Thanks all.

• 39
• 15
• 9
• 23
• 10