Inheritance of purity

deadalnix deadalnix at gmail.com
Sat Feb 25 13:53:40 PST 2012


Le 25/02/2012 22:25, Timon Gehr a écrit :
> On 02/25/2012 10:28 PM, deadalnix wrote:
>> Le 25/02/2012 21:44, Walter Bright a écrit :
>>> On 2/25/2012 9:53 AM, deadalnix wrote:
>>>> And suddenly, the override doesn't override the same thing anymore.
>>>> Which is
>>>> unnacceptable.
>>>
>>> class A {
>>> void fun() const { }
>>> void fun() { }
>>> }
>>>
>>> class B : A {
>>> override void fun() { }
>>> }
>>>
>>> ----
>>>
>>> dmd -c foo
>>> foo.d(6): Error: class foo.B use of foo.A.fun() hidden by B is
>>> deprecated
>>
>> So, how do someone override the non const version of the function but
>> not the const version ?
>
> By explicitly stating that he is aware of all the overloads:
>
> class B : A {
> alias A.fun fun;
> override void fun() { }
> }
>
> Alternatively:
>
> class B : A{
> override void fun()const{super.fun();}
> override void fun() { }
> }

So, back to the example above, someone will have to go throw the whole 
codebase and add override void fun()const{super.fun();} all over the 
place to fix the broken code ?

It is better, but still . . .


More information about the Digitalmars-d mailing list