开发者

Stack push causes critical error

I am new to C++ and working with STL container at the moment. I got a serious problem executing a nodeStack.push(startnode) - the compiler shows up a

Critical error detected c0000374

Followign code shows the function where the mentioned error occurs:

v开发者_如何学Goector<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 with 0.


try int* val = new int[adjlist.size()]; you are currently allocating a single int and initializing its value, not allocating an array of ints.

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


nodeStack.push isn't really your problem. You are declaring int* val - a pointer to int, then initializing the integer at val with the size of the list. You really want int *val = new int[adjlist.size()];


It's possible that you are using an x86 DLL; when I got this error in VS4.5, I changed my target platform to x86 and switched to .Net 4.0. That worked for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜