A stack shift causes a critical error

I am new to C ++ and am currently working with the STL container. I had a serious problem with the execution of nodeStack.push(startnode) - appears in the compiler

Fatal error c0000374 detected

The tracking function code shows the function in which the indicated error:

 vector<int> Graph::iterativeDepthSearch(map<int, vector<int>> adjlist, int startnode) { stack<int> nodeStack; vector<int> visitList; // Knotenbesuchsliste initialisieren int* val = new int(adjlist.size()); for (int i = 0; i < (int) adjlist.size(); i++) { val[i] = 0; } int cnt = 1; nodeStack.push(startnode); .... } 

The error occurs in the line nodeStack.push(startnode); , startnode is initialized to 0.

+4
source share
3 answers

try int* val = new int[adjlist.size()]; you currently allocate one int and initialize its value, rather than allocating an array from int.

The stack structure is corrupted because it is next to your pointer in the memory stack.

+15
source

nodeStack.push is not your problem. You declare int * val - a pointer to int, and then initialize the integer to val with the size of the list. Do you really want int * val = new int [adjlist.size ()];

+4
source

Perhaps you are using the x86 DLL; when I received this error in VS4.5, I changed my target platform to x86 and switched to .Net 4.0. It worked for me.

-1
source

All Articles