Hey guys and girls. I am working on a project that needs to use templates. My professor didnt go over teh use of them in class, nor is our book very descriptive of them. Im assuming they are way easier than i make them seem, but some help , tips, etc would be very helpful.
My assignment is to make a doubly linked list, using templates etc. I have a basic skeleton for the code which is all placed within a single .h file. (We have a driver program given to use for use with our code as the main.cpp file).
//BASIC HEADER FILES HERE
template <class T>
struct DNode
{
Deque(const T &);
T * item, * prev, * next;
};
template <class T>
class Deque
{
private:
T * qFront, * qRear, * data;
public:
Deque();
bool empty();
};
/****************************************************************
FUNCTION: Deque()
ARGUMENTS: int
RETURNS: None
NOTES: this is the Deque constructor
****************************************************************/
template <class T>
Deque::Deque()
{
qFront = qRear = NULL;
}
/****************************************************************
FUNCTION: Deque()
ARGUMENTS: int
RETURNS: None
NOTES: this is the Deque constructor
****************************************************************/
template <class T>
DNode::Deque(const T& item)
{
prev = next = NULL;
data = item;
}
/****************************************************************
FUNCTION: empty()
ARGUMENTS: None
RETURNS: bool
NOTES: finds out if the deque is empty or not
****************************************************************/
template <class T>
bool Deque<T>::empty()
{
return (qFront == NULL && qRear == NULL);
}
#endif //END OF DEQUE.H
I have a problem trying to compile this using the driver program in a dev project.
Here is the start code:
int main()
{
Deque<int> deque1;
cout << "deque 1 is ";
if (deque1.empty())
cout << "empty" << endl;
else
cout << "not empty" << endl;
And i get the following error message when attempting to compile.
[Linker error] undefined reference to `Deque<int>::Deque()'
Which means that the Deque<int> deque1 defined in main.cpp cannot find the constructor correct? This being the case, if im correct in thinkin that way, the problem lies with the way the templates work/need to be set. Could you guys give me a hand in sorting out the basics of the templates/and if its not a template problem, point that out too!!!
Thank you so much in advance