csci>g++ -c queue.cpp
csci>g++ queue.o project6.cpp
Undefined first referenced
symbol in file
Queue<int>::return_index() /var/tmp//ccHbZwrM.o
Queue<int>::enqueue(int) /var/tmp//ccHbZwrM.o
Queue<int>::dequeue() /var/tmp//ccHbZwrM.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
These are my errors. As you can see, my implementation file compiles, but does not compile with the client program. What is going on? I checked all the templates and they seem fine. Can anyone point me the right direction.
queue.h
#ifndef QUEUE_H
#define QUEUE_H
const int MAX = 100;
template <class Item>
class Queue{
public:
Queue()
{
front = 0;
rear = MAX - 1;
count = 0;
data[MAX] = 0;
}
void display();
void enqueue(Item);
Item dequeue();
int return_index();
private:
Item data[MAX];
int front, count, rear;
int next_index(int i)
{
return (i + 1) % MAX;
}
};
#endif
queue.cpp(implementation file)
#include "queue.h"
#include <iostream>
using namespace std;
template <class Item>
void Queue<Item>::display()
{
int index = front;
for (int i = 0; i < count; ++i)
{
cout << data[index] << endl;
index = next_index(index);
}
}
template <class Item>
void Queue<Item>::enqueue(Item entry)
{
rear = next_index(rear);
data[rear] = entry;
++count;
}
template <class Item>
Item Queue<Item>::dequeue()
{
Item dequeued;
dequeued = data[front];
front = next_index(front);
--count;
return dequeued;
}
template <class Item>
int Queue<Item>::return_index()
{
return count;
}
project6.cpp(client file)
#include <iostream>
#include "queue.h"
#include <iomanip>
using namespace std;
int get_lowest(Queue<int> [], int);
int main()
{
int qs_pair, maxtran, prob, dur, seed;
int count(0); // The number of customers served
int entry_time(0); // When each served customer arrived
int wait_sum(0); // Sum of waiting times
cout << "how many queue/server pair(s)? ";
cin >> qs_pair;
cout << "\nthe max time for customer transaction --> ";
cin >> maxtran;
cout << "\nthe probability a customer will arrive --> ";
cin >> prob;
cout << "\nduration of simulation(at least 1) --> ";
cin >> dur;
cout << "\nenter an integer seed --> ";
cin >> seed;
srand(seed);
Queue<int> line[qs_pair]; //needs fixing
int trans_time[qs_pair]; //time remaining in a transaction
for(int i = 0; i < qs_pair; i++)// needs fixing
{
trans_time[i] = 0;
}
int lowest;
int trans_time_c; // trans_time counter
for(int time = 0; time < dur; time++)
{
cout << "Tick " << time << " " << endl;
if(rand() % 100 < prob)
{
lowest = get_lowest(line, qs_pair);
line[lowest].enqueue(time);
}
//good above
for(trans_time_c = 0; trans_time_c < qs_pair; trans_time_c++)
{
if(trans_time[trans_time_c] == 0)
{
if(line[trans_time_c].return_index() != 0)
{
entry_time = line[trans_time_c].dequeue();
wait_sum += (time - entry_time);
++count;
trans_time[trans_time_c] = (rand() % maxtran) + 1;
}
}
else
{
trans_time[trans_time_c] -= 1;
}
}
for(int i = 0; i < qs_pair; i++)//needs fixing
{
cout << "line " << i << " trans time " << trans_time[i] << endl;
}
cout << endl;
}
}
int get_lowest(Queue<int> line[], int qs_pair)
{
int temp = line[0].return_index();
int temp_i = 0;
for(int i = 0; i < qs_pair; i++)
{
if(line[i].return_index() == 0)
return i;
else if((i == qs_pair - 1) && line[qs_pair - 1].return_index() < temp)
{
temp = line[qs_pair - 1].return_index();
temp_i = qs_pair - 1;
}
else
{
if(line[i].return_index() > temp)
{
}
else
{
temp = line[i].return_index();
temp_i = i;
}
}
}
return temp_i;
}