好的,我有这个问题:
Unhandled exception at 0x00261A46 in CompGeometry.exe: 0xC0000005: Access violation writing location 0xCDCDCDED.
First-chance exception at 0x00261A46 in CompGeometry.exe: 0xC0000005: Access violation writing location 0xCDCDCDED.
这发生在使用调试器的这行代码中:
edges.tail->next->a = newEdge->a;
这是该特定部分的所有代码:
/* non-empty list -- add it */
if (edges.head != NULL)
{
printf("1 %d, %d\n", newEdge->a.x, newEdge->a.y);
printf("2 %d, %d\n", newEdge->b.x, newEdge->b.y);
//edges.tail->next = new hull::EDGE;
edges.tail->next->a = newEdge->a;
edges.tail->next->b = newEdge->b;
newEdge->next = NULL;
edges.tail->a.x = newEdge->a.x;
edges.tail->a.y = newEdge->a.y;
edges.tail->b.x = newEdge->b.x;
edges.tail->b.y = newEdge->b.y;
}
/* empty list -- 1st item */
else
{
edges.head = newEdge;
edges.tail = newEdge;
newEdge->next = NULL;
}
这是我的边缘结构和我的边缘结构:
typedef struct line {
VERTEX a;
VERTEX b;
struct line *next;
} EDGE;
struct edges {
int size;
EDGE* head;
EDGE* tail;
};
//all edges of the hull
struct edges edges;
因此,我尝试将一条 EDGE 添加到名为“edges”的 EDGES 数组中。
请帮忙!
最佳答案
问题出在你的
edges.tail->next
你必须确定是否
edges.tail
和
edges.tail->next
在访问它之前不为 NULL。
关于c++ - 指向结构体访问冲突写入位置的指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26829824/