Method hiding
bearophile
bearophileHUGS at lycos.com
Thu May 27 14:38:43 PDT 2010
Steven Schveighoffer:
> This is actually the first question I posted on this newsgroup in 2007.
I am very late then, sorry for not asking this is D.learn.
> It's called method "hijacking", look for it on the D website for a
> thorough explanation. Note that this is actually the default behavior in
> C++ (I didn't know until I asked the question and tried it, it's pretty
> obscure).
I have read this, about in the middle:
http://www.digitalmars.com/d/2.0/hijack.html
Thank you for the explanations and thanks to Walter for that page. I vaguely remember reading that page, but I did remember it only about free functions.
I appreciate D design here :-)
> But the behavior is overridable, you can do this:
>
> class B : A {
> alias A.foo foo;
> void foo(A a) {}
> }
>
> Which means "also look at A for resolving foo."
OK.
> However, doing this may lead to further issues. I think if you had a
> class C that derived from B, calling B.foo(c) would result in an ambiguity
> without a cast.
I will experiment some about this.
Thank you and bye,
bearophile
More information about the Digitalmars-d
mailing list