簡體   English   中英

C“未知類型”中的枚舉錯誤

[英]Enum Error in C “Unknown Type”

我一直得到“未知的類型名稱'的地方',即使我寫的枚舉正確我看不出我做錯了什么錯誤。謝謝

#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;

 }

你的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()
{ /* .. */ }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM