2013-07-30 90 views
0

情況:我試圖在Nodes類中創建一系列方法,所有這些方法都將使用由playerName(string)和next(listnode)組成的結構「listnode」 。我在頭文件中創建了結構,因爲我也將在主類中使用該結構。缺少類型說明符 - int假定C4430錯誤

錯誤:當我編譯,我得到一個不尋常的錯誤,它的一個錯誤「C4430:缺少類型說明符 - 假定爲int。注意:C++不支持默認INT」我得到這個錯誤像8

#ifndef STRUCTS_H 
#define STRUCTS_H 
#include <Windows.h> 
#include <string> 

typedef struct 
{ 
    string playerName; 
    listnode * next; 
} listnode; 

#endif 

回答

1

如果您正在編譯爲C++,你應該能夠做到:

struct listnode 
{ 
    string playername; 
    listnode* next; 
}; 

(這裏不需要typedef)

如果你希望能夠用C語言編譯,你將需要使用結構體的標籤名:

typedef struct listnode_tag 
{ 
    string playername; 
    struct listnode_tag* next; 
} listnode; 

(顯然string可能需要std::string在C++中工作,你應該在這個文件中有一個#include <string>,只是爲了確保它在它自己的「完整」)。

1

string住在std命名空間中,所以請參考std::string。你也不必在C++中typedef語法:

#include <string> 

struct listnode 
{ 
    std::string playerName; 
    listnode * next; 
}; 
1

讓它:

typedef struct listnode 
{    ^^^^^^^^ 
    std::string playerName; 
    ^^^^^ 
    struct listnode * next; 
    ^^^^^^ 
} listnode; 
+1

如果是C++,則不需要typedef。 –

+0

正確 - 我不確定OP是否要使用C/C++兼容的頭文件,但是我想不是因爲他使用了''。 –

相關問題