I've built an almost complete version of a dynamic queue template, but I keep getting unresolved externals. I've compiled the program without writing anything in main and I get no errors, but when I try to call any of the functions, I get errors.
I've gone through my header and implementation files, and fixed a few things, but nothing has fixed the errors I'm getting. I'll post the code here:
#ifndef QUEUETEMPLATE_H
#define QUEUETEMPLATE_H
#include <iostream>
usingnamespace std;
#pragma once
template <class T>
class QueueTemplate
{
private:
//Struct for nodes
struct qNode
{
T data; //Node's value
qNode *next; //Pointer
};
qNode *front; //Pointer, holds the front of the queue
qNode *back; //Pointer, holds the back of the queue
int queueNum; //Tracks number of items in queue
public:
//Constructor
QueueTemplate();
//Destructor
~QueueTemplate();
//Operations
void enqueue(T);
void dequeue(T &);
bool isEmpty() const;
void destroyQueue();
};
#endif
//Driver for QueueTemplate class
#include <iostream>
#include <string>
#include "QueueTemplate.h"
usingnamespace std;
int main()
{
string word;
int number;
//Creating queues
QueueTemplate<string> strque;
QueueTemplate<int> intque;
cout << "We have a queue to hold names." << endl;
cout << "Our queue of names is " << (strque.isEmpty() ? "Empty" : "Not Empty");
cout << "We will put three names into our queue." << endl;
//Enqueueing names...
for (int n = 0; n < 3; n++)
{
cout << "Enter name: " << endl;
getline(cin, word);
strque.enqueue(word);
}
cout << "Our queue of names is " << (strque.isEmpty() ? "still empty" : "no longer empty");
cout << "The program will read back the names in the order they were entered.\n";
for (int n = 0; n < 3; n++)
{
strque.dequeue(word);
cout << word << endl;
}
return 0;
}
I appreciate any help. I'm sure this is yet another small problem I'm repeatedly overlooking.
I can't believe I forgot to combine definition and implementation. Looking back at my book, it mentioned this with templates, but I'd completely forgotten about it.