我目前正在尝试为一个名为totheright的结构指定一个指针(这是一个链表节点)。指向结构/列表的指针当前位于另一个称为矩形的结构中。我尝试这样做时遇到错误。
currect->right = malloc(sizeof(totheright));
righthead = current->right;
以下是函数中的声明:
rect *currect = NULL;
totheright *righthead = NULL;
标题中的结构定义:
typedef struct _totheright {
int rect;
struct _totheright *right;
} totheright;
typedef struct _rect {
int thisrect;
struct totheright *right;
int left;
double width;
double height;
double xcord;
double ycord;
struct _rect *next;
} rect;
答案 0 :(得分:1)
结构right
中的字段rect
在使用struct
或totheright
之前不应该struct _totheright
:
typedef struct _rect {
int thisrect;
//struct totheright *right; // was
totheright *right; // fixed
//struct _totheright *right; // that would be ok as well
int left;
double width;
double height;
double xcord;
double ycord;
struct _rect *next;
} rect;