C2143 缺少 ';'在“*”和 C 4430 之前缺少类型说明符 - 假定为 int。注意 c++ 不支持 default-int
C2143 missing ';' before '*' & C 4430 missing type specifier - int assumed. note c++ does not support default-int
此代码采用多个输入文件,然后使用 getline 函数将输入文件中的行放入链表中。我想创建链接列表存在问题,因为它给出了错误 "error C2039: 'down' : is not a member of '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;
}
}
您需要转发声明 Commands
结构:
struct Commands;
struct Functions
{
string fname;
Functions *right;
Commands *down;
};
struct Commands
{
string command;
Commands *next;
};
在Functions
之前添加Commands
的前向声明:
struct Commands;
struct Functions {
...
}
此代码采用多个输入文件,然后使用 getline 函数将输入文件中的行放入链表中。我想创建链接列表存在问题,因为它给出了错误 "error C2039: 'down' : is not a member of '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;
}
}
您需要转发声明 Commands
结构:
struct Commands;
struct Functions
{
string fname;
Functions *right;
Commands *down;
};
struct Commands
{
string command;
Commands *next;
};
在Functions
之前添加Commands
的前向声明:
struct Commands;
struct Functions {
...
}