STL list and referencing

This is a discussion on STL list and referencing within the C++ Programming forums, part of the General Programming Boards category; Hi, I have an STL list which holds references to a list of entities which are dynamic in my program. ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    12

    STL list and referencing

    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

    Code:
    	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
    Life is a piece of chocolates

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,338
    It looks like your problem is not with the STL list, but with your Entity class or the pointers you are adding to the list. The list holds pointers, and your code looks correct (you are properly calling functions of whichever Entity the stored pointer is pointing to). In other words, from the standpoint of using the STL, that code is fine.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Books and LibraryThing.com
    By Kanshu in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 05-11-2009, 10:37 AM
  2. Problem with linked list and shared memory
    By Sirfabius in forum C Programming
    Replies: 10
    Last Post: 11-10-2008, 03:45 PM
  3. CircleMUD (amateur linked list problem)
    By FragerZ in forum C Programming
    Replies: 2
    Last Post: 01-21-2008, 07:12 PM
  4. Linked List
    By al_engler in forum C Programming
    Replies: 2
    Last Post: 12-26-2006, 10:17 AM
  5. Another Linked List plee
    By Dragoncaster131 in forum C Programming
    Replies: 3
    Last Post: 05-15-2004, 05:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21