From -7583192643807251260
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,297e1191220ad2df
X-Google-Attributes: gidf78e5,public
From: "Gabor Greif" <gabor@no.netopia.com>
Subject: Re: [Q] function member template in a template class
Date: 1999/05/10
Message-ID: <B35C6DB3-625F1@192.168.1.8>#1/1
X-Deja-AN: 476157153
Content-Transfer-Encoding: 7bit
Approved: Valentin Bonnard <bonnard@clipper.ens.fr>
References: <hinnant-0405991054460001@ith3-285.twcny.rr.com>
X-Original-Date: 10 May 99 11:04:17 +0200
Content-Type: text/plain; charset=US-ASCII
X-Newsgroups-TO: nntp://news.noris.de/comp.std.c++
Organization: noris network GmbH, Nuernberg, Germany
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUANzbTqKwEuYhIxRhxAQGu9AH9FkVFwpG8NGe0feTN/Keq6/FEY6T0y6bM QfkkoHmKxKSzXykoDptrx76fq9ta8vfr7jjc2BPw8WR97IRNOBeFfA== =YZjP
X-News-Servers: news.noris.de
Mime-Version: 1.0
Newsgroups: comp.std.c++

On my question , how to externally define a member template function of a
templated class

On Fri, May 7, 1999 18:43 Uhr, Howard Hinnant
<mailto:hinnant@_anti-spam_metrowerks.com> wrote:
>This ought to do it:
>
>template <int I, typename T>
>struct Res { };
>
>
>template <int I, typename T>
>struct Bar
>{
>        template <int J>
>        typename Res<J, T> foo(void);
>};
>
>template <int I, typename T>
>template <int J>
>typename Res<J, T>
>Bar<I, T>::foo(void)
>{
>   return Res<J, T>();
>}
>
>int main()
>{
>   Bar<1, int> b;
>   b.foo<2>();
>}
>
>-Howard
>


Thanks to Howard and also Siemel, who responded privately. The latter has
pointed out, that my original code contained a non-conformant line:

>        typename Res<J, T> foo(void);

Here typename is not allowed, since it is inferrable that Res<J, T> is a
type. The typename would be necessary to disambiguate the access to some
member in Res<J, T>, such as a typedef or a nested class.

He has also brought to my attention that calling foo as in

>   b.foo<2>();

will not work, since the "<" could be parsed as a smaller operator.

The correct version would be:

>  b.template foo<2>();

It seems that Howard and me are using the same compiler ;-)

	Gabor
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]



