undefined reference will be the death of me

So I'm sure this program will work as soon as this error is handled, I honestly have no clue WHAT is going on, the function is clearly defined and I checked all my spelling, my parameter lists, everything checks out and yet I keep getting.


main.cpp:(.text+0xfd): undefined reference to `CQueue<int>::Enqueue(int&)'
main.cpp:(.text+0x1c1): undefined reference to `CQueue<int>::Dequeue(int&)'
main.cpp:(.text+0x298): undefined reference to `CQueue<int>::DestroyQueue()'


here is the .h file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
template <class QueueType>
class CQueue
{
public:
    CQueue(void) {}
    CQueue(const CQueue &object);
    ~CQueue(void) {}

    void    CreateQueue(void);
    int     DestroyQueue(void);
    void    Dequeue(void);
    void    Dequeue(QueueType &newItem);
    void    Enqueue(QueueType &newItem);
    void    Retrieve(QueueType &frontItem) const;
    bool    IsQueueEmpty(void) const { return (m_list.IsListEmpty()); }

    CQueue& operator=(const CQueue &rhs);

private:
    CSimpleList<QueueType> m_list;

};


and here are the 3 functions that are being called out.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
template <class QueueType>
int CQueue<QueueType>::DestroyQueue(void)
{
    int temp = m_list.GetNumItems();
    m_list.DestroyList();
    return temp;
}

template <class QueueType>
void CQueue<QueueType>::Enqueue(QueueType &newItem)
{
    try
    {
        m_list.InsertItem(m_list.GetNumItems(), newItem);
    }
    catch(const CListEx &listEx)
    {
        if(LIST_FULL == listEx.GetExType())
        {
            throw CQueueEx(QUEUE_FULL);
        }
        else
        {
            throw CQueueEx(QUEUE_ERROR);
        }
    }
}
template <class QueueType>
void CQueue<QueueType>::Dequeue(QueueType &newItem)
{
    try
    {
        m_list.GetListItem(0, newItem);
        m_list.RemoveItem(0);
    }
    catch(const CListEx &listEx)
    {
        if(LIST_EMPTY == listEx.GetExType())
        {
            throw CQueueEx(QUEUE_EMPTY);
        }
        else
        {
            throw CQueueEx(QUEUE_ERROR);
        }
    }
}


if there is anything else you need to see please let me know.
Are your function template definitions part of the header?
http://www.cplusplus.com/forum/general/127993/
http://stackoverflow.com/questions/1724036/splitting-templated-c-classes-into-hpp-cpp-files-is-it-possible (courtesy of xismn for pointing out this link in another thread)
Last edited on
Thank you sir, in my tired stupor I seemed to have forgotten a vital fact that when working with templates you cannot separate the functions from the .h file into a separate .cpp file. I thank you for your links. You are a gentleman and a scholar.
Topic archived. No new replies allowed.