Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 28 Dec 2007 00:15:50 +0800
From:      Erich Dollansky <oceanare@pacific.net.sg>
To:        "Heiko Wundram (Beenic)" <wundram@beenic.net>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: OT: C++ Template Functions
Message-ID:  <4773CFB6.8020008@pacific.net.sg>
In-Reply-To: <200712271701.38821.wundram@beenic.net>
References:  <200712271621.12167.wundram@beenic.net> <4773C7E5.3090302@pacific.net.sg> <200712271701.38821.wundram@beenic.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi,

Heiko Wundram (Beenic) wrote:
> Am Donnerstag, 27. Dezember 2007 16:42:29 schrieb Erich Dollansky:
>> Heiko Wundram (Beenic) wrote:
>>> The problem is most probably related to the fact that the group of member
>>> functions is only discriminated by return type (i.e., the template
>>> parameter defines the return type), not by parameter (which could be
>>> inferred).
>> if nothing got changed over the last years, it is not possible to do
>> this by definition.
>>
>> When I needed this the last time, I used a enum as an additonal
>> parameter to achieve this.
>>
>> I know, it is not perfect, but it leads to what I intended.
>>
>> It should work here too. I know, it is not the prefect solution.
> 
> This is perfectly possible (nowadays? I've been using this for quite some time 
> now, but not in the "complexity" of the original mail). Take the following 
> code, for example, which compiles perfectly fine with gcc (and works, of 
> course):
> 
> """
> template <typename T, typename U>
> T* newop(U test)
> {
> 	return new T(test);
> }
> 
wasn't your question that you have a class with several member functions 
which would all be identical except of the return type?

It is not a problem outside a class, the problem comes when you want to 
do this inside a class as you also would define a class with an - in 
theory - unknown and unlimited number of member functions.

Erich



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4773CFB6.8020008>