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 
    void MakeEmpty();
    bool IsEmpty() const;
    bool IsFull() const;
    void Enqueue(ItemType);
    void Dequeue(ItemType&);
    int front, rear,max;
    ItemType items;
    int maxQ;

and the queue.cpp (constructor and destructor)

#include <iostream>
#include <fstream>

using namespace std;
#include "queue.h"

template <class ItemType>
   items= new ItemType[maxQ];

template <class ItemType>
   delete [] items;

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

Recommended Answers

All 2 Replies

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?

Great that worked, thanks man!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.