Jump to content
  • Advertisement
Sign in to follow this  
guardian24

Programming Game AI by Example - EdgeIterator problem with VS2005

This topic is 4172 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

From SparseGraph.h, which is among the code for this book: template <class node_type, class edge_type> class SparseGraph { typedef edge_type EdgeType; . typedef std::list<edge_type> EdgeList; typedef std::vector<EdgeList> EdgeListVector; . EdgeListVector m_Edges; . //now comes the nested iterator class: class ConstEdgeIterator { typename EdgeList::const_iterator curEdge; const SparseGraph<node_type, edge_type>& G; const int NodeIndex; //so far no problems const EdgeType* begin() { curEdge = G.m_Edges[NodeIndex].begin(); return &(*curEdge); } //there it is: const EdgeType* next() { ++curEdge; return &(*curEdge); //debug assert: list iterator not deferencable //Just crashes in Release build } . }; . }; The ConstEdgeIterator is then used like this: graph_type::ConstEdgeIterator ConstEdgeItr(graph, node); for (const graph_type::EdgeType* pE=ConstEdgeItr.begin(); !ConstEdgeItr.end();pE=ConstEdgeItr.next()) { . . } It builds without problems, and it actually runs when built with VS6. The problem might be that VS2005 follows the C++ Standard more closely? If so, how could this problem be circumvented?

Share this post


Link to post
Share on other sites
Advertisement
hmmm very strange I haven't had any issues with any of the code form the book. The code looks like it should work fine, I've never got that assertion before when dereferencing an iterator for std::list. What does it do when you run in debug mode?

Share this post


Link to post
Share on other sites
It seems that the next() method tries to dereference the end() iterator of the std::list.
When at the end of the std::list, curEdge becomes equal to G.m_Edges[NodeIndex].end(), then next() tries to return it.
VS6 ate it, but it shouldnt have, it seems.

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!