STL lists and referencing

Started by
4 comments, last by CRACK123 18 years, 10 months ago
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
The more applications I write, more I find out how less I know
Advertisement
Quote:Original post by CRACK123
when 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.
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?
Quote:Original post by Andrew Russell

Finally, 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.


The more applications I write, more I find out how less I know
I think there's a hotkey that does that... (anyone know what it is?)
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.
The more applications I write, more I find out how less I know

This topic is closed to new replies.

Advertisement