我已经开始了5周的c ++编程。 我正在研究一个程序并使用链表来在程序中存储数据。所以这就是我所做的,而且程序没有编译。如果社区能够解决这些错误,我会很高兴。
// C ++ Assignment.cpp:定义控制台应用程序的入口点。 //
x:Bind
答案 0 :(得分:0)
首先,名称空间list
中已存在std
类型。如果您using namespace std;
,则无法在名为list
的类型中声明。您永远不应该为自己的任何类型list
命名,也不要使用名称空间std
。
例如,将您的类型list
重命名为mylist
。像这样调整你的代码:
...
struct mylist;
mylist *next;
...
struct mylist
{
...
};
bool empty(mylist *head);
...
void firstElement(myList *&head, myList *&last, int nic, string name, int contact, string address, int customerId, string todaysVehicle, string vnum){
head = last = new myList;
head->next = NULL;
head->nic = nic;
head->contact = contact;
head->address = address;
head->customerId = customerId;
head->name = name;
head->todaysVehicle = todaysVehicle;
head->vnum = vnum;
head->status = status;
head->serviceType = serviceType;
}
void insertCustomer(myList *&head, myList *&last, int nic, string name, int contact, string address, int customerId, string todaysVehicle, string vnum){
if (empty(head))
firstElement(head, last, nic, name, contact, address, customerId, todaysVehicle, vnum);
else {
last->next = new myList;
last = last->next;
last->next = NULL;
last->nic = nic;
last->contact = contact;
last->address = address;
last->customerId = customerId;
last->name = name;
last->todaysVehicle = todaysVehicle;
last->vnum = vnum;
last->status = status;
last->serviceType = serviceType;
}
}
除此之外,我建议使用std::list
而不是自己动手。