bug: method override via overload

pragma pragma_member at pathlink.com
Mon Feb 20 07:56:00 PST 2006


Apologies if this has been posted before:

The compiler seems to accept the method overload for 'bar' with a different type
of argument, yet it fails to resolve the correct overload when that method is
called.  Near as I can tell, since both int and Foo are technically the same
type, the base class method is being completly overriden - is this a type
covariance issue?

One can change the return type of the overriden method to match the overriding
one, suggesting that the compiler wants to treat both methods as distinct (it
doesn't complain that they match).  Perhaps Typedef is to blame here?

# 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
# }


- Eric Anderton at yahoo



More information about the Digitalmars-d-bugs mailing list