How should overruling of overloaded functions work?

Kristian kjkilpi at gmail.com
Sun Aug 20 08:26:46 PDT 2006


On Sat, 19 Aug 2006 18:09:25 +0300, Kristian <kjkilpi at gmail.com> wrote:
> 3)
> If the overloading does not work for derived classes, then the following  
> common case does not work without the alias hack:
>
> class String {...}
>
> class Base {
>      void f(String s) {...}
>      //these functions are provided for convenience...
>      final void f(int v) {
>          f(new String(v));
>          }
>      final void f(float v) {
>          f(new String(v));
>          }
> }
>
> class Derived : Base {
>      void f(String s) {...}  //overrule the main function that does all  
> the work
> }


Okey, okey, why doesn't someone tell me that this actually works!? :)

The functions 'f(int)' and 'f(float)' are not hidden from Derived because  
they're final. Nice!

This was the main reason I protested against the current overload function  
hiding. But because it do work, I will fell silent (and look a bit  
embarrassed). ;)

This enables me to write these convenience functions without the need of  
rewriting (or alias hacking) them in subclasses. Non-final functions  
should be reimplemented anyway (if someone wants to use alias hacking for  
those, be my guest).



More information about the Digitalmars-d mailing list