[英]Received segfault when dereferencing iterator which has been initialized to list.begin
当取消引用已初始化为list.begin()的迭代器时,我遇到了段错误。
list<data>::iterator it;
for(int i=0; i< n; i++)
{
it = (list_empty[i]).begin();
while(it != (list_empty[i]).end())
{
cout<<"PROBLEM HERE: size="<<it->process.size<<endl;
//cout<<"log file i="<<i<<endl;
log_file_start(current_time, it,"list of empty");
it++;
}
}
这是来自gdb的错误:
Program received signal SIGSEGV, Segmentation fault.
[Switching to process 2888]
0x0804ecc0 in log_file_buddy (list_delay=..., list_vp=...,
list_empty=0x805a00c, method=..., current_time=0, n=10)
at fuctions_of_mm.cpp:425
425 cout<<"PROBLEM HERE: size="<<it->process.size << endl;
bt已满的gdb输出显示迭代器为NULL。
(gdb) bt full
#0 0x0804ecc0 in log_file_buddy (list_delay=..., list_vp=...,
list_empty=0x805a00c, method=..., current_time=0, n=10)
at fuctions_of_mm.cpp:425
i = 8
it = {_M_node = 0x0}
out = <incomplete type>
尽管迭代器为NULL, it != (list_empty[i]).end()
评估it != (list_empty[i]).end()
。 怎么了?
编辑:对不起,遗漏。 就是这样: list_empty = new list<data>[n];
N是给定的参数,表示该参数:2 ^ {N} = Size_of_Memory
编辑#2:这是定义:
typedef struct data{
int position;
vp proccess;
int delay;
int current_life;
int time_start;
int time_stop;
int part_of_memory;
bool operator ==(const data& st)
{
return proccess.pid == st.proccess.pid;
}
}data;
和vp的定义:
typedef struct {
int size;
int pid;//prosdiorisths diergasias
}vp
n的值: n = 10
。
list_empty的声明是list <data> * list_empty; 。
这对我有用:
#include <list>
using std::list;
const int n = 10;
typedef struct {
int size;
int pid;//prosdiorisths diergasias
}vp;
typedef struct data{
int position;
vp process;
int delay;
int current_life;
int time_start;
int time_stop;
int part_of_memory;
bool operator ==(const data& st)
{
return process.pid == st.process.pid;
}
}data;
int main()
{
list<data>* list_empty = new list<data>[n];
list<data>::iterator it;
for(int i=0; i< n; i++)
{
it = (list_empty[i]).begin();
while(it != (list_empty[i]).end())
{
cout<<"PROBLEM HERE: size="<<it->process.size<<endl;
//cout<<"log file i="<<i<<endl;
//log_file_start(current_time, it,"list of empty");
it++;
}
}
}
什么是it
?
it_empty = new list<data>::iterator[n];
for(int i=0; i< n; i++)
{
auto it = (list_empty[i]).begin();
while(it != (list_empty[i]).end())
{
cout<<"PROBLEM HERE: size="<<it->process.size<<endl;
//cout<<"log file i="<<i<<endl;
log_file_start(current_time, it,"list of empty");
it++;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.