Inheritance of purity

deadalnix deadalnix at gmail.com
Sat Feb 18 04:50:05 PST 2012


Le 17/02/2012 17:17, Andrei Alexandrescu a écrit :
> Agreed. Timon, could you please submit to bugzilla?
>
> BTW I referred to the converse problem:
>
> class C {
> void foo() {}
> void foo() const {}
> }
>
> class D : C {
> void foo() const {} // should only override the const overload
> }
>
>
> Andrei
>
> On 2/17/12 8:00 AM, kenji hara wrote:
>> I think this is a current implementation problem.
>>
>> In this case, just `override void foo()` in class D should override
>> the method in C.
>> And `void foo()const` should be a new overlodad of foo.
>>
>> Kenji Hara
>>
>> 2012/2/17 Timon Gehr<timon.gehr at gmx.ch>:
>>> On 02/17/2012 02:33 PM, Timon Gehr wrote:
>>>>
>>>>
>>>> Introducing a new overload against const in a subclass is illegal:
>>>>
>>>> class C{
>>>> void foo(){}
>>>> }
>>>> class D : C{
>>>> override void foo(){}
>>>> override void foo()const{}
>>>> }
>>>>
>>>> Error: D.foo multiple overrides of same function
>>>
>>>
>>> Oops...
>>>
>>> I meant
>>>
>>>
>>> class C{
>>> void foo(){}
>>> }
>>>
>>> class D:C{
>>> override void foo(){}
>>> void foo()const{}
>>> }
>>>
>>> The error message is the same though.
>

I guess that is such a case, const should be explicited to get rid of 
abiguous code.


More information about the Digitalmars-d mailing list