2016-04-24 64 views
1

袋implementation.h:當我嘗試聲明bag結構體時出錯?

typedef struct node { 
    struct node *next; 
    char *element; 
    int repeats; 
} Node; 

typedef struct{ 
    size_t size; 
    Node *head; 
}Bag; 

線,在bag.c誤差(其包括bag.h其包括袋implementation.h):

Bag bag_union(Bag bag1, Bag bag2){ 
    Bag union; 
    return bag1; 

} 

錯誤:

bag.c: In function 'bag_union': 
bag.c:188:12: error: expected '{' before ';' token 
bag.c:188:7: error: two or more data types in declaration specifiers 
make: *** [bag.o] Error 1 

如果我嘗試編譯而不創建那個包,那麼它工作正常。什麼是問題?

+1

您不能有一個名爲'union'的變量。 –

+0

lmao修復它謝謝你 – Jenny

回答

2

union是C中的一個保留字,所以你不能有這樣的變量。只需重命名它。

1

union是一個keyword它不能用於變量。 This是定義變量的規則。