EscapeCharacter
11-20-2002, 12:32 AM
im getting this undefined reference on a template class im making and i cant for the life of me figure out why this is happening, perhaps another set of eyes can point in the right direction.
sframe.h:
#ifndef __SFRAME__
#define __SFRAME__
//#include "sobject.h"
#include "smenu.h"
#include "common.h"
/* This will be the main container class
* all top level widgets will only be able to
* be added to this widget
*/
template <class T>
class SFrame{
public:
SFrame();
// virtual ~SFrame();
void AddObject(T *, uint);
void DeleteObject(uint);
void Pack(uint);
private:
T *list;
uint side;
};
#endif
sframe.cpp:
#include "sframe.h"
template <class T>
SFrame<T>::SFrame(){}
template<class T>
void SFrame<T>::AddObject(T *type, uint s){
if(type == NULL){
type = new T();
type->SetNext(NULL);
type->SetPrev(NULL);
Pack(NORTH);
}
}
template<class T>
void SFrame<T>::Pack(uint s){
side = s;
}
main.cpp:
...
#include "smenu.h" // contains the definition of SMenuBar
#include "sframe.h"
...
SFrame<SMenuBar> *test = new SFrame<SMenuBar>; //line 121
...
that last line is where it dies when linking i get:
g++ sobject.o common.o smenu.o sframe.o simage.o planet.o main.o -o thirdconflict -L/usr/X11R6/lib -lX11 -lXpm
main.o: In function `main':
/home/escape/src/ThirdConflict/ThirdConflict-0.0.6/main.cpp:121: undefined reference to `SFrame<SMenuBar>::SFrame(void)'
collect2: ld returned 1 exit status
make: *** [thirdconflict] Error 1
sframe.h:
#ifndef __SFRAME__
#define __SFRAME__
//#include "sobject.h"
#include "smenu.h"
#include "common.h"
/* This will be the main container class
* all top level widgets will only be able to
* be added to this widget
*/
template <class T>
class SFrame{
public:
SFrame();
// virtual ~SFrame();
void AddObject(T *, uint);
void DeleteObject(uint);
void Pack(uint);
private:
T *list;
uint side;
};
#endif
sframe.cpp:
#include "sframe.h"
template <class T>
SFrame<T>::SFrame(){}
template<class T>
void SFrame<T>::AddObject(T *type, uint s){
if(type == NULL){
type = new T();
type->SetNext(NULL);
type->SetPrev(NULL);
Pack(NORTH);
}
}
template<class T>
void SFrame<T>::Pack(uint s){
side = s;
}
main.cpp:
...
#include "smenu.h" // contains the definition of SMenuBar
#include "sframe.h"
...
SFrame<SMenuBar> *test = new SFrame<SMenuBar>; //line 121
...
that last line is where it dies when linking i get:
g++ sobject.o common.o smenu.o sframe.o simage.o planet.o main.o -o thirdconflict -L/usr/X11R6/lib -lX11 -lXpm
main.o: In function `main':
/home/escape/src/ThirdConflict/ThirdConflict-0.0.6/main.cpp:121: undefined reference to `SFrame<SMenuBar>::SFrame(void)'
collect2: ld returned 1 exit status
make: *** [thirdconflict] Error 1