2013-03-24 34 views
2

這裏時,我使用的節點結構......錯誤「類型‘X *’不能分配給類型的實體值‘X *’」使用typedef結構

typedef struct 
{ 
    struct Node* next; 
    struct Node* previous; 
    void* data; 
} Node; 

這裏是我使用的將它們連接在這些線上

void linkNodes(Node* first, Node* second) 
{ 
    if (first != NULL) 
     first->next = second; 

    if (second != NULL) 
     second->previous = first; 
} 

現在Visual Studio是給我的智能感知(少)錯誤的函數

IntelliSense: a value of type "Node *" cannot be assigned to an entity of type "Node *" 

任何人都可以解釋正確的方法來做到這一點? Visual Studio將編譯它並運行它查找,它也可以在我的Mac上運行,但在我的學校服務器上崩潰。

編輯:我想用的memcpy的,但是這是相當cheasy

+0

你的錯誤信息是「錯誤的」,你在這裏報告,它應該是'「節點*」不能分配給類型「結構節點*」'的實體。要麼你有一個非常糟糕的編譯器來混淆事物(不太可能),這會表明你以某種方式碰巧把你的代碼編譯爲C++。不要這樣做,C和C++是不同的語言,爲此,您的問題就是一個很好的例子。 – 2013-03-24 08:13:56

回答

4

我認爲這個問題是不存在結構稱爲節點,只有一個typedef。嘗試

typedef struct Node { .... 
1

與Deepu的答案類似,但是可以讓您的代碼編譯的版本。你的結構更改爲以下:

typedef struct Node // <-- add "Node" 
{ 
    struct Node* next; 
    struct Node* previous; 
    void* data; 
}Node; // <-- Optional 

void linkNodes(Node* first, Node* second) 
{  
    if (first != NULL) 
     first->next = second; 

    if (second != NULL) 
     second->previous = first; 
} 
0

用C定義的structtypedef最好的struct聲明本身之前完成。

typedef struct Node Node; // forward declaration of struct and typedef 

struct Node 
{ 
    Node* next;   // here you only need to use the typedef, now 
    Node* previous; 
    void* data; 
}; 
相關問題