Thread: Can't iterate empty stl list

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Sweden
    Posts
    92

    Can't iterate empty stl list

    Problem resolved!
    Quite embarassing but:
    I forgot to allocate the Game instance
    m_pGame = new Game(); fixed it.




    I have a STL list which I know is empty, but I still do as always and write a for-loop that looks like this:
    Code:
    typedef list<shared_ptr<Player> > PlayerList;
    
    class Game
    {
    public:
    	bool Init(class NetworkManager* pNm);
    	bool Update(unsigned int deltaMilli);
    	void OnClientConnect(shared_ptr<class Socket> pSocket);
    protected:
    	PlayerList m_Players;
    };
    
    bool Game::Update(unsigned int deltaMilli)
    {
    	for (PlayerList::iterator i = m_Players.begin(); i != m_Players.end(); ++i) //Crash!
    	{
    		(*i)->Update(deltaMilli);
    	}
    	return true;
    }
    At the line commented crash, the application crashes due to memory access violation in the list. I have used similar code many times before with sucess and I am very confused why this isn't working anymore. I have also tried with a vector and the same results showed up.

    Error message:
    Code:
    Unhandled exception at 0x0000000140014c65 in Application.exe: 0xC0000005: Access violation reading location 0xffffffffffffffff.
    I have no compilation warnings, but this linker warning:
    Code:
    1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
    The project is built under 64-bits debug mode.

    Would really appreciate some help on this tough one as I am completely clueless.

    Thanks in advance

    Regards
    Daniel
    Last edited by The Wazaa; 06-23-2007 at 10:32 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help! Placement of nodes in a Linked List
    By lostmyshadow in forum C Programming
    Replies: 6
    Last Post: 12-17-2007, 01:21 PM
  2. Problem with linked list ADT and incomplete structure
    By prawntoast in forum C Programming
    Replies: 1
    Last Post: 04-30-2005, 01:29 AM
  3. Replies: 6
    Last Post: 03-02-2005, 02:45 AM
  4. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  5. problem with structures and linked list
    By Gkitty in forum C Programming
    Replies: 6
    Last Post: 12-12-2002, 06:40 PM