c++ - Unhandled exception at 0x001e1078 in Dijkstra's_Algorithm.exe: 0xC0000005: Access violation reading location 0xbaadf00d -


i'm setting pointer of state class pointer of node access violation don't know problem?

the exception here :iosfwd

static int __clrcall_or_cdecl compare(const _elem *_first1, const _elem *_first2,         size_t _count)         {   // compare [_first1, _first1 + _count) [_first2, ...)         return (_cstd memcmp(_first1, _first2, _count));         } 

my code in dijkstrastate.h

void setcurrent(vertex<t>* v)     {         current = v ;     } 

in graph.h

private member: dijkstrastate<type>* states ;` in constructor: states = new dijkstrastate<type>(); template <class type> void graph<type>::add_vertex(vertex<type> input) {        type vertex_data = input.get_data() ;     //check vertex not exist     if(indexes.find(vertex_data) == indexes.end())     {         indexes[input.get_data()] = count ;         vertices[count] = input ;         states[count].setcurrent(&(vertices[count]));//////////////////////////         count ++ ;     } } 

input parameter of function. can think of local variable initialized value passed in caller. parameter variable go out of scope when function returns. saving pointer input in call setcurrent, leaving invalid pointer , undefined behavior if try use pointer after add_vertex finishes.

you haven't shown enough code know how fix it. don't know states or count comes or why need save pointer variable.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -