Click to See Complete Forum and Search --> : template issues with explicit specialization


nlgonsal
May 28th, 2002, 03:10 PM
This was my template problem in Borland C++ Builder 5.0. I have a template class called HPoint_nD<class T, class D>. I also have another template class called Basic2DArray<class T>. The Basic2DArray has a friend function called initBasic2DArray(Basic2DArray<class T>& , const int, const int). Now this function is only overloaded (or in the template case - explicit specialization) when the Basic2DArray parameter passed to it is HPoint_nD<T,D>. In the overloading, another function called initBasic2DArrayHpoint(Basic2DArray<class T>& , const int, const int) is called, where the HPoint_nD template class parameter is handled differently. Now the HPoint_nD template class has only 4 classes which are actually used. These are HPoint_nD<float,2>, HPoint_nD<float,3>, HPoint_nD<double,2>, HPoint_nD<double,3>. The only time I do not get a linker error when I try to use the Basic2DArray<Hpoint_nD<T,D> > is when the HPoint_nD<double,2> is used. All the other ones result in the linker error, "Unresolved external error with void initBasic2DArrayHpoint(Basic2DArray<class T>& , const int, const int)." The class definitions for the 4 HPoint_nD classes are similar and the explicit instantiations are also similar. Why do you think this is happenning ? Is it just Borland acting weird ? Or is there something about template instatiation and explicit specialization I am not doing ? If you need the files to look at, I will send them.
Thanks
Regards
Nitin

proxima centaur
May 28th, 2002, 03:18 PM
The only time I got a similar error is by having the templates defined in a DLL.

You then have to make sure you "instanciate" the code for all the types you want to use outside of the DLL or you'll get linker errors.

Other than that, there's nothing that I can think of, off the top of my head.