2012-10-07 55 views
-4

我工作的學校鏈表上,我得到一噸的錯誤。我敢肯定,大概有隻有一件事錯了我的代碼,但我似乎無法找到它我已經評論了我的大部分代碼,所以我不需要在這裏粘貼200行,主要的錯誤仍然顯示,雖然只是少了幾次缺少「(」前「*」

錯誤是:

error C2143: syntax error : missing '{' before '*'  

我有大概50-75錯誤一起之前,我註釋掉我的代碼這些準則彈出,但仍有少數與此代碼。任何幫助,將不勝感激。

//main.c 
#define BUFFER_SIZE 1000 
#include<stdio.h> 
#include<stdlib.h> 
#include"ListElmt.h" 
#include"List.h" 
#include"ListData.h" 

int main(int argc, char *argv[]){ 
} 

//List.c 
#include<stdlib.h> 
#include"List.h" 
#include"ListElmt.h" 
#include"ListData.h" 

//List.h 
struct List{ 
int size; 
struct ListElmt *head; 
struct ListElmt *tail; 
}; 

//ListData.h 
struct ListData { 
int hour; 
int min; 
double temp; 
int AC; 
}; 

//ListElmt.h 
struct ListElmt { 
ListData *data; 
ListElmt *next; 
ListElmt *prev; 
}; 
+0

這是C或C++?在C中,結構體名稱不是自動鍵入的名稱。 –

+0

是的'ListElmt'一個錯字的成員'struct'遺漏,或者是你的實際代碼? – jpm

+1

....和可愛請,***使用***空格。 'int main(int argc,char * argv []){}'*只是傷害。* – 2012-10-07 05:54:17

回答

3

您需要轉發聲明結構,如果他們沒有在頭文件中聲明。

因此,List.h需要前向聲明struct ListElmt,而ListElmt.h需要前向聲明struct ListData

此外,在C你必須在ListElmt.h,除非你使用一個明確的typedefListDataListElmt之前使用struct由於結構名並不屬於類型名稱。

2

你錯過了struct關鍵字

struct ListElmt { 
struct ListData *data; 
struct ListElmt *next; 
struct ListElmt *prev; 
};