aliasing base methods

Kristian Kilpi kjkilpi at gmail.com
Mon Feb 26 03:47:07 PST 2007


On Sun, 25 Feb 2007 16:13:01 +0200, Frank Benoit (keinfarbton)  
<benoit at tionex.removethispart.de> wrote:

>
> My point is, i want this strange rules to be removed.
> And I want the override keyword not to be a useless thing.
>
> I propose:
> 1.) make an overload not hide base implementations
> 2.) make the override keyword required, to make it useful.
> 3.) remove the interface reimplementation rule.
>
> What do you think?


I, also, don't like that an overload or override will hide base functions.  
I think
requiring the 'override' keyword would make code more readable. But what if
other cases (see below) would also require explicit syntax? (I don't know  
what
the full implications of this would be, etc; just some quick thoughts.)


Ok, there are the following five cases:

1) Define a new function (i.e. the base class doesn't have one with the  
same name).

2a) Override a function; don't hide other functions with the same name.
2b) Override a function; hide other functions with the same name.

3a) Add an overload for a function; don't hide other functions with the  
same name.
3b) Add an overload for a function; hide other functions with the same  
name.

(I think I haven't ever wanted/needed to use the cases 2b and 3b, though,  
but I guess
that's just me.)


New rules would be:

A) The 'override' keyword is required for the case 2a.

B) A new keyword 'overload' is required for the case 3a. (I don't know if  
'overload'
is a right word for it because it's similar to 'override'. I use it here  
though.)

C) A new keyword 'renew' (or something) is required for the cases 2b and  
3b.


For example:

   class Base {
     int foo();
     int foo(int);
   }

   class Derived : Base {
     int bar();                //ok

     int foo();                //error; 'Base' has 'int foo()'
     renew int foo();          //ok (hides 'int foo(int)')

     override int foo();       //ok
     override int foo(float);  //error; 'Base' has no 'int foo(float)'

     overload int foo();       //error; 'Base' has 'int foo()'
     overload int foo(float);  //ok
   }


For templates, there should also be extra keywords to allow easy code  
generation.
For example, <X> == override || overload, <X> is some keyword.



More information about the Digitalmars-d mailing list