CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2002
    Posts
    18

    template issues with explicit specialization

    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

  2. #2
    Join Date
    May 2002
    Location
    Quebec City, Canada
    Posts
    374
    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.
    Martin Breton
    3D vision software developer and system integrator.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured