Linker probs with template classes

Jon Anderson janderson at onelink.com
Mon Jan 10 18:43:38 GMT 2000


> template <class T>
> circularArray<T>::circularArray(int size){
>       arraySize = size;
> }

I had this problem too for a while.  The compiler doesn't always handle
template instatiation nicely when they are in separate files.  You can solve
this problem by forward declaring the class in the circularArray.cpp file
like this:

template class circularArray<int>;
template class circularArray<float>;
template class circularArray<MyClass>;
etc...

(I think that's the right syntax.  It might be 'class template' instead. )

This forces to the compiler to instantiate those class templates in the
current code module.
(By the way, Tom Swan's "GNU C++ for Linux" book that was just published is
very excellent, and covers alot of stuff like this.


Jon







More information about the KDevelop mailing list