我正在使用unix来测试我的cpp代码。并且它一直有这个错误。
未定义的符号coffeeShop :: ~coffeeShop()coffeeShop :: coffeeShop()首先在文件/var/tmp//ccvhyGI4.o /var/tmp//ccvhyGI4.o
中引用coffeeShop :: analysisFile(std :: basic_string,std :: allocator>)/ var / tmp//ccwBzN3b.o
我认为问题出在分析文件中......所以就是这样。
#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <windows.h>
#include "coffeeShop.h"
#include "order.h"
#include "orderNode.h"
#include "customer.h"
#include "myEvent.h"
#include "openEvent.h"
#include "closeEvent.h"
#include "arrivalEvent.h"
#include "startServiceEvent.h"
#include "completeServiceEvent.h"
using namespace std;
coffeeShop::coffeeShop(){
rugTst = 0;
rugTwt = 0;
expTst = 0;
expTwt = 0;
rugNum=0;
expNum=0;
curTime = 1;
rugTime = 1;
expTime = 1;
expressOpened=false;
eventList = new GenericList();
openList = new GenericList();
closeList = new GenericList();
COFFEE=new item("COFFEE", 2, true);
TEA=new item("TEA", 3, true);
DONUT=new item("DONUT", 1, true);
ICEDCAPP=new item("ICEDCAPP", 6, false);
BAGEL=new item("BAGEL", 4, true);
PANINI=new item("PANINI", 12, false);
custQueue=new myQueue();
}
coffeeShop::~coffeeShop(){
delete COFFEE;
delete TEA;
delete DONUT;
delete ICEDCAPP;
delete BAGEL;
delete PANINI;
delete eventList;
delete custQueue;
delete openList;
delete closeList;
}
void coffeeShop::analysisFile(string fileName){
char* buf = new char[100];
ifstream in(fileName, ios::in);
if (!in.is_open())
{
cout << "Error opening file\n";
exit(0);
}
while (!in.eof())
{
in.getline(buf, 100);
istringstream input(buf);
string str = "";
int time;
input >> time;
input >> str;
if (str == "OPEN")
{
eo = new openEvent();
eo->setTime(time);
eventList->insert(eo);
openList->insert(eo);
}
else if (str == "CLOSE")
{
ec = new closeEvent();
ec->setTime(time);
eventList->insert(ec);
closeList->insert(ec);
}
else
{
string name;
int num;
customer* cust = new customer(time);
while (input >> name&&input >> num)
{
cust->orderFood(new orderNode(createItem(name, num)));
}
custQueue->push(cust);
}
}
eventNode* eoHead = openList->getHead();
eventNode* ecHead = closeList->getHead();
eo =(openEvent *) eoHead->node;
ec =(closeEvent *)ecHead->node;
while (!custQueue->isEmpty())
{
customer* c = custQueue->pop();
if (rugTime > eo->beginTime)
{
if (eoHead->next)
{
eoHead = eoHead->next;
eo = (openEvent *)eoHead->node;
}
expressOpened = true;
}
int time = c->getArriveTime();
curTime = time;
receiveCustomer(c, time);
if (c->getArriveTime() > ec->beginTime)
{
if (ecHead->next)
{
ecHead = ecHead->next;
ec = (closeEvent *)ecHead->node;
}
expressOpened = false;
}
}
print();
}
void coffeeShop::print(){
cout << "Simulation begins...\n" << endl;
eventNode* temp = eventList->getHead();
while (temp){
temp->node->print();
temp=temp->next;
}
summary();
}
order* coffeeShop::createItem(string name, int num)
{
if (name == COFFEE->getName())
{
return new order(new item("COFFEE", 2, true), num);
}
else if (name == DONUT->getName())
{
return new order(new item("DONUT", 1, true), num);
}
else if (name == TEA->getName())
{
return new order(new item("TEA", 3, true), num);
}
else if (name == ICEDCAPP->getName())
{
return new order(new item("ICEDCAPP", 6, false), num);
}
else if (name == BAGEL->getName())
{
return new order(new item("BAGEL", 4, true), num);
}
else
{
return new order(new item("PANINI", 12, false), num);
}
}
void coffeeShop::receiveCustomer(customer* cust,int time)
{
eventList->insert(new arrivalEvent(time,cust));
if (!expressOpened)
{
cust->setWaitTime(rugTime-time);
rugTwt += cust->getWaitTime();
curTime += cust->getWaitTime();
eventList->insert(new startServiceEvent(curTime, cust, true));
rugNum++;
rugTst += cust->getServiceTime();
}
else
{
if (expressOpened&&expTime < rugTime)
{
if (expTime!=1)
{
cust->setWaitTime(expTime - time);
}
else
{
cust->setWaitTime(eo->beginTime - time);
}
expTwt += cust->getWaitTime();
curTime += cust->getWaitTime();
eventList->insert(new startServiceEvent(curTime, cust, false));
expNum++;
expTst += cust->getServiceTime();
}
else
{
cust->setWaitTime(rugTime - time);
rugTwt += cust->getWaitTime();
curTime += cust->getWaitTime();
eventList->insert(new startServiceEvent(curTime, cust, true));
rugNum++;
rugTst += cust->getServiceTime();
}
}
curTime += cust->getServiceTime();
eventList->insert(new completeServiceEvent(curTime, cust));
if (expressOpened&&expTime < rugTime)
{
expTime = curTime;
}
else
{
rugTime = curTime;
}
}
void coffeeShop::summary(){
cout << "...All Service complete.Final Summary :\n" << endl;
cout << "Lane Total Total Total Average Average\n" << endl;
cout << " Customers Service Time Wait Time Service Time Wait Time\n" << endl;
cout << "Regular" << setiosflags(ios::left) << setw(10) << rugNum << setw(10) << rugTst << setw(10) << rugTwt << setw(10) << setprecision(3) << (rugNum == 0 ? 0 : rugTst*1.0 / rugNum) << setw(10) << (rugNum == 0 ? 0 : rugTwt*1.0 / rugNum) << "\n" << endl;
cout << "Express" << setiosflags(ios::left) << setw(10) << expNum << setw(10) << expTst << setw(10) << expTwt << setw(10) << setprecision(3) << (expNum == 0 ? 0 : expTst*1.0 / expNum) << setw(10) << (expNum == 0 ? 0 : expTwt*1.0 / expNum) << "\n" << endl;
cout << "End of Processing" << endl;
}
这是我的头文件
#include "myEvent.h"
#include "openEvent.h"
#include "closeEvent.h"
#include "GenericList.h"
#include "item.h"
#include "order.h"
#include "customer.h"
#include "myQueue.h"
#include <string>
using namespace std;
class coffeeShop{
private:
int rugNum;
int expNum;
int rugTst;
int rugTwt;
int expTst;
int expTwt;
int curTime;
int rugTime;
int expTime;
bool expressOpened;
GenericList* eventList;
GenericList* openList;
GenericList* closeList;
openEvent* eo;
closeEvent* ec;
item* COFFEE;
item* TEA;
item* DONUT;
item* ICEDCAPP;
item* BAGEL;
item* PANINI;
myQueue* custQueue;
public:
coffeeShop();
~coffeeShop();
void analysisFile(string fileName);
void print();
order* createItem(string name,int num);
void receiveCustomer(customer* cust,int time);
void summary();
};