我正在尝试实现一个堆栈,但不了解不透明指针的使用。这里是我的报关表:
/* incomplete type */
typedef struct stack_t *stack;
/* create a new stack, have to call this first */
stack new_stack(void);
这是我的堆栈结构和 new_stack 函数:
struct stack_t {
int count;
struct node_t {
void *data;
struct node_t *next;
} *head;
};
stack new_stack(void)
{
struct stack_t new;
new.count = 0;
new.head->next = NULL;
return new;
}
在我看来,我正在返回新堆栈的地址,但这会在返回新堆栈时引发编译错误。我究竟做错了什么?