Topic: Nested templates & compilers


Author: 76717.3337@compuserve.com (Jan Klier)
Date: 1996/05/06
Raw View
I ran across an interesting problem the other day and was wondering what the
standard requires for this case and what the majority of the compilers do with
it:

(I don't remember the exact syntax and I don't have the code in front of me,
so forgive me if it won't compile, it wouldn't matter for the argument
anyway).

I have a list class that is defined using a template:

template <class Data>
CL_List<Data>
{ ... }

And I have a function template that takes such a list as an argument:

template <class ID_t,class CL_List<Data> >
ReadObject(ID_t,CL_List<Data>)
{ ... }

My program then uses several instances for this function within a caching
module with different types for the Data template.

When I compile this on AIX with the xlC compiler it works just fine. If I
compile it with g++, version 2.6.3 I get undefined symbols for these functions
without any warning.
I then compiled it also with the HPUX CC compiler and get a warning that the
compiler cannot identify the template functions because he cannot see the
difference between these functions that lies only within the Data template
within the nested CL_List class. To make the code work on HPUX I had to add an
additional dummy parameter with of the same class Data and pass it into the
function to enable the compiler to uniqueley identify all instances and
produce the correct code.

       Jan
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu
]