Method overloading and inheritance
Steven Schveighoffer
schveiguy at yahoo.com
Tue Jul 7 06:14:45 PDT 2009
On Mon, 06 Jul 2009 15:54:29 -0400, Jarrett Billingsley
<jarrett.billingsley at gmail.com> wrote:
> On Mon, Jul 6, 2009 at 3:12 PM, Steven
> Schveighoffer<schveiguy at yahoo.com> wrote:
>> In addition, the workaround to get the desired
>> behavior is pretty straightforward (the alias base.function function
>> syntax).
>
> It's particularly annoying, though, that there is no way to do this for
> ctors.
AFAIK, there's no way to do that in Java either. What's unique about
constructors is that you can't access the base constructors *except* from
another constructor. A member, however is accessible, even if it is
hidden. For example, this workaround makes it somewhat foolish:
class C
{
void foo(int a);
}
class D : C
{
void foo(string s);
}
auto d = new D;
d.foo(1); // compile error
C c = d;
c.foo(1); // ok. or sometimes a runtime error (ugh!)
Just by simple retyping (no casting), you can access the base members.
constructors are different though. What you really want is to say that
the derived class does not redefine construction, or only modifies it. I
think actually, allowing base constructors might be an easier thing to
implement in the spec/compiler, because no vtables are involved.
-Steve
More information about the Digitalmars-d
mailing list