www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - override and overload

From http://www.digitalmars.com/d/function.html
... To consider the base class's functions in the overload resolution
process, use an AliasDeclaration

I am not happy with this mechanism. You can loose all base
implementations silently, when doing a method implementation and forget
the alias. Why silently? See this visitor example:

class A    { void accept( Visitor v ){ v.visit(this); } ... }
class B : A{ void accept( Visitor v ){ v.visit(this); } ... }
class C : B{ void accept( Visitor v ){ v.visit(this); } ... }

class Visitor{
  void visit( A a ){} // do nothing
  void visit( B a ){} // do nothing
  void visit( C a ){} // do nothing
}
class TraversVisitor : Visitor{
  void visit( A a ){..} // do a traversion
  void visit( B a ){..}
  void visit( C a ){..}
}
class MyVisitor : TraversVisitor {
  void visit( A a ){..} // (1)
}

In (1), the "alias TraversVisitor.visit visit;" is missing, I simply
forgot it. But there is no error. Why? Because visit(A a ) matches all
possible calls. This is really a bad thing. The sequence of called
methods is completely different.

I want to suggest the following:
1.) change the overloading rule, so it does not hide the derived methods.
2.) make keyword "override" required for all overriding methods. Throw a
compiler error if the "override" is missing.
3.) For consistency, require also "override" if implementing a interface
or abstract method.
Nov 13 2006