*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.
精彩评论