Topic: Instantiation of recursive templates


Author: andreww@dcs.rhbnc.ac.uk (Andrew Waters)
Date: 26 Apr 1994 16:31:51 GMT
Raw View
Does the working paper have anything to say on recursive templates.  For example:

 template <class T>
 class Pair
 {
 };

 template <class T>
 class Set
 {
 public:
   Set<Pair<T> > operator *(const &Set<T>);
 };

 int main()
 {
   Set<int> int_set;
   return 0;
 }

This is taken from an actual program.  Here we have the set operator `*' which
pairs every element in the first set with every element in the second set.
However,  when instantiating the Set<int> the operator requires Set<Pair<int> >
which requires Set<Pair<Pair<int > > > etc.  The operator `*' is used on the
original Set<int>,  but never for Set<Pair<int> >.

-------------------------------------------------------------------------------
Computer Science Department                     | mail: andreww@dcs.rhbnc.ac.uk
Royal Holloway, University of London            | tel:  +44 784 443425 (direct)
Egham Hill, Egham, Surrey. TW20 0EX. England    |
-------------------------------------------------------------------------------