gpt4 book ai didi

c - 错误: member reference base type '*****' (aka '*****' ) is not a structure or union

转载 作者:行者123 更新时间:2023-11-30 20:36:55 26 4
gpt4 key购买 nike

当我尝试访问通过引用传递的函数中的结构时,编译器显示此错误:

error: member reference base type 'Pila' (aka 'struct tipoCelda *') is not a structure or union
**p = p->sig;**

这是头文件中结构体的原型(prototype):

typedef int tipoElemento;

typedef struct tipoCelda {
tipoElemento elemento;
struct tipoCelda * sig;
} tipoCelda;

typedef tipoCelda * Pila;

这是我收到错误的函数:

tipoElemento pilaSuprime (Pila *p){

tipoElemento borrado;

if (pilaVacia(p) == 1)
printf ("\n\nNO SE PUEDE BORRAR.La pila esta vacia\n");
else{
borrado = p->elemento;

p->elemento = 0;
p = p->sig;
}

return borrado;
}

由于这三行我收到消息:

borrado = p->elemento;

p->elemento = 0;
p = p->sig;

我在main中声明堆栈,然后调用该函数:

Pila variablePila;

//////OTHER ACTIONS//////

pilaSuprime(variablePila)

我试图删除一个像堆栈一样的链表节点,但我无法编译它。

最佳答案

我没有以正确的方式插入节点。现在用这个方法就可以了!

int pilaInserta (Pila *p,tipoElemento elemento){

Pila nuevo;

nuevo = (Pila) malloc (sizeof(Pila));
if (nuevo == NULL){
printf ("Error al crear el nuevo nodo de la pila\n");
return 0;
}

nuevo->elemento = elemento;
if (*p == NULL){ //Si estaba vacia y es el primero
*p = nuevo;
nuevo->sig = NULL;
}
else{
nuevo->sig = *p; //Apuntamos al que estaba primero
*p = nuevo;
}

return 0;

}

删除节点就像一位用户写道:

tipoElemento pilaSuprime (Pila *p){

tipoElemento borrado;

if (pilaVacia(p) == 1)
printf ("\n\nNO SE PUEDE BORRAR.La pila esta vacia\n");
else{
borrado = (*p)->elemento;

(*p)->elemento = 0;
p = (*p)->sig;

printf ("\n\nEl elemento borrado es: %d\n",borrado);
}

return borrado;
}

关于c - 错误: member reference base type '*****' (aka '*****' ) is not a structure or union,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34681510/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com