Problem with linking template classes derived from abstract template classes
S. Peschke
peschke.at.nt.dot.uni-paderborn.dot.de@nt.uni-paderborn.de
Tue Sep 28 10:51:00 GMT 2004
Hi there!
I have a problem with linking template classes derived from abstract template
classes.
First of all, here's the simplified code:
==================================================
File cX.h:
--------------------------------------------------
#ifndef CX_H
#define CX_H
template < class T >
class CX
{
...
virtual void vx ( ) = 0;
void v1 ( );
}
// class is abstract
#endif
==================================================
File cX.cpp
--------------------------------------------------
#include "cX.h"
...
template < class T >
void CX < T > :: v1 ( )
{
...
}
==================================================
File cY.h:
--------------------------------------------------
#ifndef CY_H
#define CY_H
#include "cX.h"
template < class T >
class CY : public CX < T >
{
...
virtual void vx ( );
void v2 ( );
}
// class is not abstract
#endif
==================================================
File cY.cpp
--------------------------------------------------
#include "cY.h"
...
template < class T >
void CX < T > :: vx ( )
{
...
}
template < class T >
void CX < T > :: v2 ( )
{
...
}
template class cY < float >;
==================================================
File cZ.h:
--------------------------------------------------
#ifndef CZ_H
#define CZ_H
#include "cX.h"
template < class T >
class CZ : public CX < T >
{
...
virtual void vx ( );
void v3 ( );
}
// class is not abstract
#endif
==================================================
File cZ.h:
--------------------------------------------------
...
template class cZ < float >;
==================================================
File main.cpp
--------------------------------------------------
#include "cY.h"
int main ( );
{
CY < float > cY ( );
CZ < float > cZ ( );
...
}
==================================================
The last lines of cY.cpp and cZ.cpp were placed to prevent the "undefined
reference to ..." problem while linking. This works fine if both CY and CZ
wouldn't be derived from the abstract class CX (->
http://www.myri.com/scs/L3/doc/gcc_11.html or
http://www.cygwin.com/ml/cygwin/1997-11/msg00429.html).
But i don't know what's to do in this particular case with CX. Placing
"template class CX < float >" in the last line of cX.cpp doesn't work ('cause
it's abstract, i think).
So, does anyone have an answer or a hint how to do it that both linker and
compiler can do their jobs?
Thank you in advance,
Sven
PS: I'm using g++ 3.3.1 on Suse Linux 8.2 i386 german.
More information about the Gcc-help
mailing list