Suggestion: a shortcut for calling the base member function with unchanged parameters

Kristian kjkilpi at gmail.com
Mon Aug 21 10:41:23 PDT 2006


Let we have the following two classes:

class Base {
     void f(int index, float val1, float val2, bool isScalingUsed) {...}
}

class Derived : Base {
     void f(int index, float val1, float val2, bool isScalingUsed) {
         //do something
         ...

         super.f(index, val1, val2, isScalingUsed);
     }
}

At the end of 'Derived.f()' we call the corresponding function of the base  
class without modifing any of the parameters. How many times you have done  
it? I have done it quite many times.

The parameter list of 'super.f()' is redundant code.
You can make a typo or two when writing it. In addition, when the  
parameter list of 'f()' is modified, or some of the paramters are renamed,  
you have to change 'super.f(...)' also. It's tedious and you can easily  
make an error, or you simply forget to do that.

So, why not get rid of that redundant code?

Let there be some kind of shortcut for it. For example:

     super.f($);  //== 'super.f(index, val1, val2, isScalingUsed)'

Naturally this kind of shortcutting should be possible with the  
constructors also (i.e. "super($);").



More information about the Digitalmars-d mailing list