Real World usage of D, Today (was Re: challenge #2: implement the varargs_reduce metafunction)

James Dennett jdennett at acm.org
Fri Jan 26 23:28:46 PST 2007


Walter Bright wrote:
> James Dennett wrote:
>> Could you maybe explain what you mean by "C++-style
>> overriding" as opposed to Java-style overriding?  In
>> what way is D more like C++ here than like Java?
> 
> In C++, overriding one function in a base class prevents use of any of
> the base class function's overloads. In Java, you can override one
> overload and inherit the rest.

OK; I'd say this is a name lookup difference, not a
difference in how overriding is done.

In C++ it doesn't prevent the use of the base class
function's overloads: they can still be used if you
name their scope, or if you bring them into the scope
of the derived class with a using declaration.  (It
certainly does prevent certain idiomatic uses of those
base class functions unless you add a using declaration.
It turns out to generally be a bad idea to overload
virtual functions for design reasons unrelated to the
specifics of a particular language though, so this
isn't much of an issue in practice.)

In Java, lookup is done by signature, not just name,
and there's no such thing as "hiding" of a name in
a base class by a name in a derived class.

Both systems have their pros and cons, and D could
reasonably resemble either, so long as the choice
"feels" consistent with other decisions in the design
of D.

-- James



More information about the Digitalmars-d mailing list