Topic: Circular template types


Author: gyro@netcom.com (Scott L. Burson)
Date: Sat, 4 Dec 1993 00:32:12 GMT
Raw View
Consider the following program fragment.

   template<class T> class B;

   template<class T>
   class A {
 B<T>* b;
   };

   template<class T>
   class B {
 A<T> a;
   };

   A<int> a;

As you see, class A<T> holds a pointer to B<T>, while B<T> holds an instance
of A<T>.

One template processor I have used (Object Design's) handles this code without
complaint.  One I have just started using (cfront 3) can't: it complains that
the size of A<T> is not known during the instantiation of B<T>.

Obviously I think this code should be legal, especially since we have an
existence proof that it can be handled correctly.  Evidently, what ODI's
template processor is doing is somehow keeping the declarations in their
original order during expansion.  (If I put the declaration of B before that
of A, ODI's processor fails also.)

Does the draft standard address this issue?

-- Scott