C2143 缺少 '*' 之前的';' 和 C 4430 缺少类型说明符 - 假定为 int。注意 C++ 不支持 default-int

C2143 missing ';' before '*' & C 4430 missing type specifier - int assumed. note c++ does not support default-int

本文关键字:int C++ default-int 不支持 说明符 注意 缺少 C2143 4430 类型      更新时间:2023-10-16

这段代码接受几个输入文件,然后使用getline函数将输入文件中的行放在一个链表中。我猜有一个关于创建链表的问题,因为它给出了一个错误"错误C2039: 'down':不是'函数'的成员以及标题上指定的错误。我不知道C2130 &C4430 错误。

#include <iostream>
#include <fstream>
#include <string>
#include "strutils.h" 
using namespace std;
struct Functions
{
    string fname;
    Functions *right;
    Commands  *down;
};
struct Commands
{
    string command;
    Commands *next;
};
Functions *head = nullptr;
Functions *temp = nullptr;
void printLinkedList()
{
    Functions *ptr = head;
    while (ptr != nullptr)
    {
        cout << ptr->fname << endl;
        while (ptr->down != nullptr)
        {
            cout << ptr->down->command + " ";
            ptr->down = ptr->down->next;
        }
        cout << endl;
        ptr = ptr->right;
    }   
}

您需要向前声明Commands结构:

struct Commands;
struct Functions
{
    string fname;
    Functions *right;
    Commands  *down;
};
struct Commands
{
    string command;
    Commands *next;
};

Functions之前添加Commands的前向声明:

struct Commands;
struct Functions {
   ...
}