我有一个实现代码的问题,你能帮我正确运行这段代码吗?无法解析的外部错误在c + +中的链接列表中的代码
代码必须插入一个新客户,并显示所有客户..
我收到以下错误:
1> Source.obj:错误LNK2019:无法解析的外部符号“类 waitinglist __cdecl mylist(void)“(?mylist @@ YA?AVwaitinglist @@ XZ) reference in function _main 1> c:\ users \ mmm \ documents \ visual studio 2012 \ Projects \ ConsoleApplication141 \ Debug \ ConsoleApplication141.exe: fatal错误LNK1120:1个未解决的外部问题
这是Header.h
:
#include<iostream>
#include<string>
using namespace std;
class customer
{
public:
string name;
int gsize;
int status;
customer* next;
customer();
customer(string,int,int);
};
class waitinglist
{
public:
int tables; //number of occupied tables
int chairnum;
int totalcustomers;
customer*head,*tail;
waitinglist();
waitinglist(int);
void newcustomer(string,int,int);
void displayall();
};
这是Source.cpp
与main
:
#include"Header.h"
customer::customer()
{
name="";
gsize=status=0;
next=NULL;
}
customer::customer(string name1,int gsize1,int status1)
{
name=name1;
gsize=gsize1;
status=status1;
next=NULL;
}
waitinglist::waitinglist()
{
chairnum=totalcustomers=tables=0;
head=tail=NULL;
}
waitinglist::waitinglist(int val)
{
chairnum=val;
totalcustomers=0;
tables=0;
head=tail=NULL;
}
void waitinglist::newcustomer(string name1,int gsize1 ,int status1)
{
customer*tmp= new customer;
if (head==NULL) // linkedlist is empty
{
head = tail = tmp;
totalcustomers++;
}
else
{
tmp->next = head;
head = tmp;
totalcustomers++;
}
}
void waitinglist::displayall()
{
customer *tmp;
tmp = head;
while(tmp != NULL)
{
cout<<tmp->name <<" "<<tmp->gsize<<"-->";
tmp = tmp->next;
}
cout << endl;
}
int main()
{
int choice;
string namevar="";
int gsizevar=0;
int statusvar=0;
waitinglist mylist();
do
{
cout<<"Note: 1 in status means{the customer not here and 2 means the customer is here.}\n";
cout<<"Select your option.\n\n";
cout<<"(1) Add a new Customer.\n";
cout<<"(2) List all Names.\n";
cout<<"(3) Quit.\n\n";
cout<<"Enter your choice: -->";
cin>>choice;
if (1 <= choice && choice <= 2)
{
switch (choice)
{
case 1:
mylist().newcustomer(namevar,gsizevar,statusvar);
break;
case 2:
mylist().displayall();
break;
default:
cout << "Invalid choice. Enter again.\n\n";
break;
}
}
}
while (choice != 3);
return 0;
}
'waitinglist MYLIST();'最让人头疼的解析 – drescherjm
有后,我固定的,请帮我备受错误! –
***我解决了这个问题后出现很多错误***询问发布确切错误的全新问题。 – drescherjm