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

时间:2015-10-23 12:53:42

标签: c++ pointers linked-list

此代码采用多个输入文件,然后使用getline函数将输入文件中的行放入链接列表中。我想创建链表有一个问题,因为它给出了一个错误 “错误C2039:'down':不是'Functions'的成员 并且指定了标题上的错误。我不知道 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;
    }   
}

2 个答案:

答案 0 :(得分:4)

在函数之前添加命令的前向声明:

struct Commands;
struct Functions {
   ...
}

答案 1 :(得分:3)

您需要转发声明Commands结构:

struct Commands;

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