0
有人可以幫我訪問一個聯合中的指針,我不斷得到一個[錯誤]無效類型參數' - >'(有'結構節點')。下面是我的數據結構的片段在裏面:C編程:訪問一個聯盟中的指針
typedef enum{LEAF,INODE}indicator;
typedef struct twoThree{
indicator indic;
union{
struct L{
int key;
}leaf;
struct node{
int key1,key2;
struct twoThree *LC,*MC,*RC;
}iNode;
}U;
}*TTT;
void insertElem(TTT *T, int elem)
{
TTT *temp;
if(*T==NULL){
*T=initTree();
(*T)->indic = LEAF;
(*T)->U.leaf.key = elem;
}else if((*T)->indic == LEAF){
if(elem < (*T)->U.leaf.key){
(*temp)=initTree();
(*temp)->indic = INODE;
(*temp)->U.iNode.key1 = elem;
**(*temp)->U.iNode->LC = *T; /*This is my problem"->LC" part*/**
}
}
}
TTT initTree()
{
TTT T;
T=(TTT)malloc(sizeof(struct twoThree));
if(T!=NULL){
printf("Initialization of tree was successful.\n");
}else{
printf("Failed initialization of tree.\n");
}
return T;
}
如果任何人都可以對我如何在聯盟內訪問我的指針指出,這將是巨大的。多謝你們。
您有多個錯誤。對於初學者來說,當您解除引用時,「temp」指向何處? –
'typedef struct twoThree {...} * TTT' - 在大多數情況下'typedef'指針是個不錯的主意。 –
至於你的問題,'U.iNode'不是一個指向結構的指針,它是一個結構*對象*,因此你不應該使用箭頭運算符' - >'來訪問它的成員。 –