报错access violation writting location,是我malloc用错了么
typedef struct TagAgent
{
double xs, xe, xn, ys, ye, yn, WayAhead, delay, Et, alpha; //alpha的单位是度
bool arrived, collision;
int nb_sum, hnb_sum, *neighbor, *nb_rank;
}agent;
agent *craft;
craft = (agent*)malloc(sizeof(agent)*M);
for(int i=0; i<M; i++)
craft[i].neighbor = (int*)malloc(sizeof(int)*M);
报错条总是指在这一行:
craft[k].neighbor[a] = XX;
说access violation writting location
[解决办法]
craft[k].neighbor[a] = XX;
说access violation writting location
你贴的代码里没有这一句啊,哥.
[解决办法]
craft[k].neighbor[1] = i;
craft[k].neighbor[2] = i;……若能用就是越界,而且应该是运行时报错。
104 = 80+8+16;中间8是两个bool变量因边界对其得到的
[解决办法]
我调试都是从后边开始,先把一部分语句屏蔽然后运行,若还有错再把更多的语句屏蔽再运行,直到没有错误,就知道可能是在哪条语句出错了。然后再具体找这条语句是哪里错了……个人习惯……
你把M设的大点试试