2017-04-02 138 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