Thread: STL list and referencing

  1. #1
    Registered User
    Join Date
    Mar 2004

    STL list and referencing


    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())
    			vector3 view = m_pCamera->GetTarget();
    			(*itor)->SetPosition(view.x, 0.0f, view.y);
    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.

    Life is a piece of chocolates

  2. #2
    Registered User
    Join Date
    Jan 2005
    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
    By Kanshu in forum A Brief History of
    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, 04:45 PM
  3. CircleMUD (amateur linked list problem)
    By FragerZ in forum C Programming
    Replies: 2
    Last Post: 01-21-2008, 08:12 PM
  4. Linked List
    By al_engler in forum C Programming
    Replies: 2
    Last Post: 12-26-2006, 11:17 AM
  5. Another Linked List plee
    By Dragoncaster131 in forum C Programming
    Replies: 3
    Last Post: 05-15-2004, 05:40 PM