c++ - 缺少类型说明符 - int 假定为 C4430 错误

标签 c++ struct header

情况:我正在尝试在 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/

相关文章:

c++ - : file. h 与 file.cxx 中的函数实现

c++ - int64_t 背后的魔力是什么

c++ - 如何以不同方式访问结构成员

c - 字计数器 'forgetting' 关于已保存的字

php - 使用 header() 时, header 是立即发送还是在完整脚本运行后发送?

java - 使用 Retrofit 2 向所有请求添加 header

c++ - sendto 和 recvfrom 在同一个程序中?

c++ - 如何从 C++ 中的图片 (jpg) 制作图标文件?

将一个结构复制到另一个

php - 该插件没有有效的标题 - Wordpress 无法添加新插件