bug: method override via overload

Nick Nick_member at pathlink.com
Mon Feb 20 08:09:49 PST 2006


In article <dtcoqg$22lv$1 at digitaldaemon.com>, pragma says...
>
># typedef int Foo;
># 
># class Gorf{
># 	public void bar(int x){} // return type here is immaterial (try 'int')
># }
># 
># class Goat : Gorf{
># 	public int bar(Foo x){}
># }
># 
># void main(){
># 	Foo y = 0;
># 	int z = 0;
># 	Goat g = new Goat();
># 	g.bar(y); // works
># 	g.bar(z); // fails
># }

This is by design, not a bug. When you introduce members with the same name in a
child class, you automatically hide the inherited name from the parent. There
are good reasons to do this, and C++ does it the same way. Add the line

alias Gorf.bar bar;

to Goat to get it the way you want. (BTW this question comes up a lot - perhaps
it's time to make a FAQ for these groups?)

Nick





More information about the Digitalmars-d-bugs mailing list