0

Hi, I'm getting pretty frustrated with my code at this point, Im trying to implement a queue class to hold a number of integers... however dev (the compiler im using) keeps spitting out the errors

[Linker error] undefined reference to `QueueType<int>::QueueType()'
[Linker error] undefined reference to `QueueType<int>::~QueueType()'

here is the line of code of interest

{
 QueueType<int> queue;
}

the implementation

#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
#include "queue.h"
#include "image.h"

(image.cpp is where im calling this function from)
the queue.h

#ifndef QUEUE_H
#define QUEUE_H

template<class ItemType>
class QueueType 
{
 public:
    QueueType();
    ~QueueType();
    void MakeEmpty();
    bool IsEmpty() const;
    bool IsFull() const;
    void Enqueue(ItemType);
    void Dequeue(ItemType&);
 private: 
    int front, rear,max;
    ItemType items;
    int maxQ;
};
#endif

and the queue.cpp (constructor and destructor)

#include <iostream>
#include <fstream>

using namespace std;
#include "queue.h"



template <class ItemType>
QueueType<ItemType>::QueueType()
{           
   max=20;                    
   maxQ=max+1;
   front=maxQ-1;
   rear=maxQ-1;
   items= new ItemType[maxQ];
}

template <class ItemType>
QueueType<ItemType>::~QueueType()
{
   delete [] items;
}

I have already hit recompile all but Ive received the same error
any help would be appreciated

2
Contributors
2
Replies
3
Views
5 Years
Discussion Span
Last Post by bloominninja
1

For class templates, you usually can't split the code into a .h and .cpp file. Did you try putting all the code in the cpp into the header file?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.