Topic: Forward declaration of classes nested in template classes


Author: alhy@courant.SLAC.Stanford.EDU (J. Scott Berg)
Date: Wed, 22 Feb 1995 17:58:03 GMT
Raw View
Consider the following declaration:

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

As far as I can tell from the 9/20/94 WP, this is illegal (my
compilers seem to agree with me on this, unless I have the syntax
wrong).  Yet, if A were not a template class, the construct would be
legal; i.e.,

class A { class B; };
class A::B { A a; };

Am I right in thinking that the template version is illegal?  If so,
is there a reason that the template version is illegal?  If not, I
would suggest that the ANSI/ISO folks might want to allow such a
forward declaration.

Thanks

    -Scott Berg
--
J. Scott Berg       Real mail: Varian Physics; Stanford  CA  94305-4060
email: ALHY@slac.stanford.edu
phone: (415) 926-4732 (w)  (415) 854-2713 (h)




Author: jason@cygnus.com (Jason Merrill)
Date: Thu, 23 Feb 1995 07:25:54 GMT
Raw View
>>>>> J Scott Berg <alhy@courant.SLAC.Stanford.EDU> writes:

> Consider the following declaration:
> template<class T> class A { class B; };
> template<class T> class A<T>::B { A<T> a; };

> As far as I can tell from the 9/20/94 WP, this is illegal (my
> compilers seem to agree with me on this, unless I have the syntax
> wrong).

Most likely, your compilers are broken.  I don't see any reason why that
code would be disallowed by the 1/31/95 WP.

Do any compilers get this right yet?

Jason