Jump to content
  • Advertisement
Sign in to follow this  
CRACK123

STL lists and referencing

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
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 this post


Link to post
Share on other sites
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.


Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!