Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 27 Dec 2007 22:35:13 +0100
From:      =?UTF-8?B?VsOhY2xhdiBIYWlzbWFu?= <V.Haisman@sh.cvut.cz>
To:        "Heiko Wundram (Beenic)" <wundram@beenic.net>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: OT: C++ Template Functions
Message-ID:  <47741A91.1030001@sh.cvut.cz>
In-Reply-To: <200712271621.12167.wundram@beenic.net>
References:  <200712271621.12167.wundram@beenic.net>

next in thread | previous in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigDD6F5C1BFAF9589872041ECF
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



Heiko Wundram (Beenic) wrote, On 27.12.2007 16:21:
> Hey all!
>=20
> I'm currently trying to implement (and use) a C++ member function templ=
ate,=20
> but GCC won't eat the code I feed it.
>=20
> The problem is most probably related to the fact that the group of memb=
er=20
> functions is only discriminated by return type (i.e., the template para=
meter=20
> defines the return type), not by parameter (which could be inferred).
>=20
> From what I gather, the C++ spec should allow the following code to wor=
k (the=20
> following is simplified from what I have, but pretty much the same=20
> syntactically):
>=20
> """
> template <typename U>
> class Test
> {
>=20
> public:
>=20
> 	template <typename V>
> 	V test()
> 		throw()
> 	{
> 		// Some stuff.
> 	}
>=20
> };
>=20
> template <typename U, typename V>
> void test2()
> 	throw()
> {
> 	Test<V>* x =3D new Test<V>();
> 	x->test<U>();
Change this to x->template test<U>(); For explanation see 14.2/4 of the y=
ear
2003 revision of the standard.

> 	delete x;
> }
>=20
> int main(int argc, char** argv)
> {
> 	test2<int,short>();
> }
> """
>=20
> gcc doesn't compile this code, no matter what I try to change the x->te=
st<U>=20
> expression to. It does compile the code if the type of x is not defined=
 via a=20
> template parameter in test2.
>=20
> If this is against the specs, please tell me, otherwise, looking forwar=
d to=20
> any hints on what may cause this!
>=20

--
VH


--------------enigDD6F5C1BFAF9589872041ECF
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHdBqYoUFWwtEPkHIRCIG8AJwJm+dnyWTwSLRNgt58iJIPcOGGTwCfTPLW
StST+Ij37yYNJ6A8rCL4x6M=
=zipN
-----END PGP SIGNATURE-----

--------------enigDD6F5C1BFAF9589872041ECF--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?47741A91.1030001>