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

missing type specifier - int assumed C4430 error

本文关键字:假定 C4430 错误 -int 说明符 类型      更新时间:2023-10-16

情况:我正试图在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>,以确保它本身是"完整的")。

string位于std命名空间中,因此将其称为std::string。您也不需要C++中的typedef语法:

#include <string>
struct listnode
{
    std::string playerName;
    listnode * next;
};

制作:

typedef struct listnode
{              ^^^^^^^^  
    std::string playerName;
    ^^^^^
    struct listnode * next;
    ^^^^^^
} listnode;
相关文章: