auto ref

Nick Sabalausky a at a.a
Thu Dec 17 09:13:57 PST 2009


"Michel Fortin" <michel.fortin at michelf.com> wrote in message 
news:hgd9jb$26v9$1 at digitalmars.com...
> On 2009-12-17 07:09:57 -0500, KennyTM~ <kennytm at gmail.com> said:
>
>> On Dec 17, 09 19:44, Michel Fortin wrote:
>>> On 2009-12-17 01:57:50 -0500, Pelle Månsson <pelle.mansson at gmail.com> 
>>> said:
>>>
>>>> On 12/17/2009 01:05 AM, Michel Fortin wrote:
>>>>> Object? func(Object? o) {
>>>>> writeln(o.toString());
>>>>> return o;
>>>>> }
>>>>>
>>>>> MyObject o = func(new MyObject);
>>>>>
>>>>> Here, "Object?" means Object or a derived type.
>>>>>
>>>> You know, just Object means Object or a derived type. That's what
>>>> inheritance is.
>>>
>>> The idea is to be able to say in the function signature that the same
>>> type is returned, avoiding a cast that would be unnecessary otherwise.
>>> It's the same principle as for "const?", or "inout".
>>>
>>> But you're right that my definition isn't very good.
>>
>> T func(T)(T o);
>
> That would work, unless you want a virtual function.
>
> If templates were always an acceptable solution, the whole discussion 
> about passing const qualifiers from the argument to the return value 
> wouldn't be of any use either.
>

Pardon my ignorance, but why is it that templated functions can't be 
virtual?





More information about the Digitalmars-d mailing list