On Thursday, 14 February 2013 at 05:49:33 UTC, cal wrote:
And a related question:
class A
{
void foo(int i){}
void foo(Tuple!(int) i){}
}
class B: A
{
override void foo(int i){}
}
int main()
{
auto b = new B;
b.foo(tuple(5));
}
This fails to compile. Why can't B use A's tuple overload of
foo()? If I do this:
class B: A
{
override void foo(int i){}
void foo(Tuple!(int) i){} // no override keyword is
deprecated
}
The compiler warns about not using the override keyword, so it
must be seeing the function?
This looks like it comes from C++, and is a built-in protection.
If you override a single method, it will shadow all other
overloads. This makes sure you don't accidentally call something
you didn't want over-ridden. If you know what you are doing, then
you can make it explicit. C++ uses the "using" keyword. I don't
know how D does it.
http://stackoverflow.com/questions/888235/overriding-a-bases-overloaded-function-in-c