2017-04-02 142 views
1

我不斷收到「未知類型名‘地方’即使我寫的枚舉正確的,我不能看到我在做什麼錯誤的錯誤。謝謝枚舉錯誤C「未知類型」

#include <stdio.h> 
#include <stdlib.h> 
#include <ctype.h> 
#include <string.h> 
#include <math.h> 
void pass(place x); 

typedef enum{ 

house, second 

} place; 

int main() 
{ 

pass(house); 

return 0; 
} 

void pass(place x){ 

if(x == house){ 
    printf("We are in a house \n") 
    }else if(x == second){ 
    printf("We live in the second house \n"); 
} 

return; 

} 
+2

如果你仔細觀察前錯誤信息,你會看到它指向一行* befor e *實際枚舉聲明... – Evert

+1

I.e.原型'void通過(place x)的原型是怎麼樣的呢?'當你還沒有別名時''知道'place'是什麼。 – WhozCraig

+0

噢那好吧,修好了,謝謝m8 – DeadAccount

回答

2

enum place聲明是好的,但問題是你定義與地方已知函數的place存在之前先改變順序,確定你的位置枚舉,你pass()功能。

#include <stdio.h> 
#include <stdlib.h> 
#include <ctype.h> 
#include <string.h> 
#include <math.h> 


typedef enum{ 
    house, 
    second 
} place; 

void pass(place x); // This function forward declaration must be after you defined place. 

int main() 
{ /* .. */ } 
+0

噢好吧不停地混淆我謝謝男人:) – DeadAccount

+0

沒問題。很高興幫助:) – 0xDEFACED

+0

你也可以贊成嗎? – 0xDEFACED