結構領域我的代碼:如何獲得用C
main()
{
typedef struct
{
int data;
} Information;
typedef Information *PtrInformation;
typedef struct InformationListStruct *PtrInformationListStruct;
typedef struct InformationListStruct
{
PtrInformationListStruct ptrNext;
PtrInformation ptrInf;
} PtrInformationListStructElement;
//==============================
PtrInformationListStruct list;
list = (PtrInformationListStruct)malloc(sizeof(InformationListStruct));
PtrInformation ptr = (*list).ptrInf; // error !!!
}
編譯器拋出錯誤:
- 「ptrInf」不是InformationListStruct的成員,因爲該類型尚未在函數main()
定義。如果我把這個行:
typedef struct InformationListStruct *PtrInformationListStruct;
此線之後:將出現
typedef struct InformationListStruct
{
PtrInformationListStruct ptrNext;
PtrInformation ptrInf;
} PtrInformationListStructElement;
然後其他錯誤:
- 類型名稱中main()函數
- 宣言丟失; ()
如何正確獲取「ptrInf」?
只是一個小的話:把類型定義的函數體是不是一個很好的初步實踐給我。 – Synxis
你有其他錯誤嗎?當您對錯誤有疑問時,最好將錯誤添加到問題中,並最好逐字(即複製粘貼)。 –
我使用的是Unix GCC,我看到下面的錯誤: tc:函數'main': tc:22:51:錯誤:'InformationListStruct'未聲明(首次在此函數中使用) tc:22:51:注意:每個未聲明的標識符僅在其出現的每個函數中報告一次 – Viswesn