M
Matt
I'm posting this question for one of my developers who's not quite as
newsgroup-savvy. Any suggestions?
The question follows, along with relevant source code.
-Matt
I have a templated queue class as part of a statically linkable
library (in GQueue.h and .cpp below). The library compiles fine, but
when I go to use it in an executable, I get linker errors complaining
that it can not find references for any of the queue functions. I
compile just the queue class as an object file, and then perform 'nm'
on the queue object and it returns the following:
00000000 b .bss
00000000 d .data
00000000 t .text
No functions in the object file. I hard coded the queue as a string
queue and everything works fine. How can I get the templated version
to generate a valid object file so that I can leave the queue
templated and still use it in a static library rather that directly
compiling it with the executable?
---------------- GQueue.h -----------------
#ifndef GQUEUE_H
#define GQUEUE_H
#include <string>
#include <queue>
using namespace std;
template <class QE>
class GQueue
{
public:
GQueue();
~GQueue();
void push(QE element);
QE pop();
int size();
private:
queue<QE> data;
};
#endif
---------------- GQueue.cpp -----------------
#include "GQueue.h"
template <class QE>
GQueue<QE>::GQueue()
{
}
template <class QE>
GQueue<QE>::~GQueue()
{
}
template <class QE>
void GQueue<QE>:ush(QE element)
{
data.push(element);
}
template <class QE>
QE GQueue<QE>:op()
{
QE tmp = data.front();
data.pop();
return tmp;
}
template <class QE>
int GQueue<QE>::size()
{
int size = data.size();
return size;
}
newsgroup-savvy. Any suggestions?
The question follows, along with relevant source code.
-Matt
I have a templated queue class as part of a statically linkable
library (in GQueue.h and .cpp below). The library compiles fine, but
when I go to use it in an executable, I get linker errors complaining
that it can not find references for any of the queue functions. I
compile just the queue class as an object file, and then perform 'nm'
on the queue object and it returns the following:
00000000 b .bss
00000000 d .data
00000000 t .text
No functions in the object file. I hard coded the queue as a string
queue and everything works fine. How can I get the templated version
to generate a valid object file so that I can leave the queue
templated and still use it in a static library rather that directly
compiling it with the executable?
---------------- GQueue.h -----------------
#ifndef GQUEUE_H
#define GQUEUE_H
#include <string>
#include <queue>
using namespace std;
template <class QE>
class GQueue
{
public:
GQueue();
~GQueue();
void push(QE element);
QE pop();
int size();
private:
queue<QE> data;
};
#endif
---------------- GQueue.cpp -----------------
#include "GQueue.h"
template <class QE>
GQueue<QE>::GQueue()
{
}
template <class QE>
GQueue<QE>::~GQueue()
{
}
template <class QE>
void GQueue<QE>:ush(QE element)
{
data.push(element);
}
template <class QE>
QE GQueue<QE>:op()
{
QE tmp = data.front();
data.pop();
return tmp;
}
template <class QE>
int GQueue<QE>::size()
{
int size = data.size();
return size;
}