Linker probs with template classes

psycho psycho-r-us at home.com
Tue Jan 11 20:18:06 GMT 2000


syntax/~prog/?

Jon Anderson wrote:

> > 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