开发者

C++ pair delete error [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

*Update: * Finally I find the problem. The problem is like this:

pair<int,int> *findPair(){
    pair<int,int> *t = new pair<int,int> [10];
    for(int i=0;i<11;i++) // error here
    {
        t[i].first =1;
        t[i].second =2;
    }
    return t;
}

int main() {
    pair&开发者_C百科lt;int, int> * tt = findPair();
    tt[1].first =8;
    delete [] tt; // error
    return 0;
}

There is segment fault error. gcc does not show any warning for out of bounds error. In my original code, I use k as index of the pair array. k changes at each while loop and ends up with a value out of bounds. Thanks you all ans sorry for any inconvenience caused.


I copied your code into a .cc file (with the right #include), and this code works just fine. Are you sure this is where the segmentation fault is at?

If you are using linux, and have no core file, use "ulimit -c unlimited". Then you can load the core file in gdb to check where the error takes place.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜