This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Problem with forward declaration of classes with nested templates
- From: David Fang <fang at csl dot cornell dot edu>
- To: Steven Keuchel <steven dot keuchel at gmail dot com>
- Cc: <gcc-help at gcc dot gnu dot org>, "John (Eljay) Love-Jensen" <eljay at adobe dot com>
- Date: Tue, 26 Sep 2006 02:42:33 -0400 (EDT)
- Subject: Re: Problem with forward declaration of classes with nested templates
> oh, thanks i thought i simplified as much as i can. But i guess i was
> wrong. Maybe i shouldn't simplify that much. My the real problem
> occurs when using 2 recurring templates like this:
>
> -----------------
> struct a;
> struct b;
>
> struct a
> {
> template<int i>
> struct impl : public b::template impl<i>
> {};
> };
>
> struct b
> {
> template<int i>
> struct impl : public a::template impl<i-1>
> {};
> };
> -----------------
I'm not a language lawyer either (IANALL), but I believe the reason the
above is invalid is because the 'b' in public b::template impl<i> is NOT
argument dependent, and thus does not undergo two-phase lookup, but rather
normal lookup. Perhaps a real language lawyer can confirm or correct me?
Fang
> but I know i can be happy by rewriting it to:
>
> -----------------
> struct a;
> struct b;
>
> struct a
> {
> template<int i>
> struct impl;
> };
>
> struct b
> {
> template<int i>
> struct impl;
> };
>
> template<int i>
> struct a::impl : public b::template impl<i>
> {};
>
> template<int i>
> struct b::impl : public a::template impl<i-1>
> {};
> -----------------
>
> But the question still remains, why doesn't it compile. Can you name something ?
>
> Regards,
> Steven