How to use templated classes with kdevelop

Peyre peyre at sans-logis.u-strasbg.fr
Mon Oct 11 13:03:28 BST 1999


Hi

I need to derive a template class for an app I'm developing.
There's no problem with the template class itself. It's compiled and linked
correctly. In revange, when I derive it, I can't build the app anymore.

I join a short a exemple.

The declaration of the template class is:

--------------------------------------------------
#ifndef VECT_H
#define VECT_H

template<class T>
class Vect {

public:
	Vect(int = 3);
	~Vect();
	
private: // Private attributes
	/** Pointer to the first element of the vector */
  T* vectPtr;
  /** Number of components of the vector */
  int size;
};

#endif
--------------------------------------------------


It definition is:

--------------------------------------------------
#include "vect.h"

template<class T>
Vect<T>::Vect(int sz){
	if (sz < 0) exit(1);
	vectPtr = new T[size = sz];
}

template<class T>
Vect<T>::~Vect(){
	delete[] vectPtr;
}
--------------------------------------------------


The declaration of the derivated class is:

--------------------------------------------------
#ifndef POINT3D_H
#define POINT3D_H


#include "vect.h"

class Point3D : public Vect<double> {
public: 
	Point3D();
	~Point3D();
};

#endif
--------------------------------------------------


And it's definition is:

--------------------------------------------------
#include "point3d.h"

Point3D::Point3D(){
}
Point3D::~Point3D(){
}
--------------------------------------------------

The messages returned while building are the following:

--------------------------------------------------
gmake: Entering directory `/home/peyre/these/dev/learning/just2show/just2show'
cd .. && automake --gnu just2show/Makefile
cd .. && perl automoc 
cd .. \
  && CONFIG_FILES=just2show/Makefile CONFIG_HEADERS= /bin/sh ./config.status
creating just2show/Makefile
gmake: Leaving directory `/home/peyre/these/dev/learning/just2show/just2show'
gmake: Entering directory `/home/peyre/these/dev/learning/just2show/just2show'
g++ -DHAVE_CONFIG_H -I. -I. -I.. -I/usr/include -I/usr/local/qt/include  -I/usr/X11R6/include    -O3 -g3 -Wall    -c point3d.cpp
/bin/sh ../libtool --silent --mode=link g++  -O3 -g3 -Wall     -o just2show -L/usr/lib  -L/usr/X11R6/lib -rpath /usr/lib 
-rpath /usr/X11R6/lib point3d.o vect.o just2showview.o just2showdoc.o 
just2show.moc.o just2showdoc.moc.o just2showview.moc.o just2show.o main.o -lkab
-lkspell -lkfile -lkfm -lkhtmlw -lkimgio -ljpeg -ltiff -lpng -lm -ljscript
-lkdeui -lkdecore -lqt -lXext -lX11   point3d.o: In function
`Point3D::~Point3D(void)':
/home/peyre/these/dev/learning/just2show/just2show/point3d.cpp:23: undefined
reference to `Vect<double>::~Vect(void)' point3d.o: In function
`Point3D::Point3D(void)':
/home/peyre/these/dev/learning/just2show/just2show/point3d.cppgmake: Leaving
directory `/home/peyre/these/dev/learning/just2show/just2show' :21: undefined
reference to `Vect<double>::Vect(int)' collect2: ld returned 1 exit status
gmake: *** [just2show] Error 1 *** échoué ***
--------------------------------------------------


Well, could anyone help me to solve this problem (if solvable it is !)
I can't believe that KDevelop does not support templated classes which are of
main interest in C++ programming.

Thank you very much for your answers

--
Hubert Peyré
Pole API - Bd Sébastien Brant - 67400 Illkirch
Tel : +33 (0) 388 65 55 41
E-mail : peyre at dpt-info.u-strasbg.fr



More information about the KDevelop mailing list