i have a problem in implementation code, could you help me to run this code correctly ?
the code must insert a new customer and display all customers ..
I receive the following errors:
1>Source.obj : error LNK2019: unresolved external symbol "class waitinglist __cdecl mylist(void)" (?mylist@@YA?AVwaitinglist@@XZ) referenced in function _main 1>c:\users\mmm\documents\visual studio 2012\Projects\ConsoleApplication141\Debug\ConsoleApplication141.exe : fatal error LNK1120: 1 unresolved externals
This is 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();
};
And this is Source.cpp
with 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();
is interpreted as function declaration (due to the most vexing parse), the definition of which you didn't supply, and later, you're trying to call it. You're getting the linker error, because the definition could not be found.
Remove the parentheses after each mylist
occurence in main
:
waitinglist mylist; // default-construct mylist
...
mylist.newcustomer(namevar,gsizevar,statusvar); // use mylist object
...
mylist.displayall();