inheritance problem

bayo bayo.fr at gmail.com
Thu Apr 26 11:21:04 PDT 2007


Jari-Matti Mäkelä a écrit :
> bayo kirjoitti:
>> Hello, i currently use DMD 1.013 for Windows and i cant compile this code
>>
>>
>> class C1 {
>>     public void add(int i, int j) {}
>> }
>>
>> class C2 : C1 {
>>     public void add(int i) {}
>> }
>>
>> void main() {
>>     C2 c = new C2();
>>     c.add(1, 2);
>> }
>>
>> src\inheritance.d(16): function inheritance.C2.add (int) does not match
>> parameter types (int,int)
>>
>>
>> I dont use D for a long time, but i dont remember having problem like this?
>>
>> So anybody can help me:
>> *Is there a problem on my code?
> 
> Yes
> 
>> *Is it a desired limitation?
> 
> Yes, this is how inheritance works in D.
> 
>> *Can i use another version of DMD to remove this problem?
> 
> No..
> 
> ..but you can fix this by adding
> 
>   alias C1.add add;
> 
> to your C2 class.
>

Realy hard to me to understand this limitation if we can "patch" it with 

an alias, but thanks a lot for your fast help, it run well :)

>> Thanks a lot for your help.
>>
>> -bayo


More information about the Digitalmars-d-bugs mailing list