情况:我正在尝试在 Nodes 类中创建一系列方法,所有这些方法都将使用由 playerName (string) 和 next (listnode) 组成的结构“listnode”。我在头文件中创建了该结构,因为我也将在主类中使用该结构。
错误: 当我编译时,我得到一个不寻常的错误,它是一个错误“c4430:缺少类型说明符 - 假定为 int。注意:C++ 不支持默认 int”我得到这个错误就像8.
#ifndef STRUCTS_H
#define STRUCTS_H
#include <Windows.h>
#include <string>
typedef struct
{
string playerName;
listnode * next;
} listnode;
#endif
最佳答案
如果您正在编译为 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>
,只是为了确保它本身是“完整的”)。
关于c++ - 缺少类型说明符 - int 假定为 C4430 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17949318/