Overloading/Inheritance issue
Regan Heath
regan at netmail.co.nz
Thu Aug 2 04:26:14 PDT 2007
Derek Parnell wrote:
>> The reason it is done the way it is, the reason Walter gave, is that
>> this is the same behaviour C++ has. He also explained why C++ has that
>> behaviour, ...
>
> Ok, I re-read the threads again and still draw the same conclusion. Walter
> has got this one wrong. D should be better than C++, IMHO.
I'm not sure it's as simple as 'better' or worse. I think it's another
case where D makes a tradeoff and as always happens when you make a
tradeoff some people would have 'gone the other way'.
Doing it the C++ way prevents the problems Walter describes but it
requires you to manually 'alias' symbols into the derived class.
Doing it the Java way (as many people seem to expect, more intuitive?)
doesn't require you to 'alias' the symbols into the derived class but
you are vulnerable to the problems Walter describes (I believe this was
prooven in that old thread).
So the tradeoff is safety/explicit/control (C++ way) vs
brevity/intuitiveness (Java way).
I would have thought that given your personal preference for being
explicit in many cases you would prefer the C++ approach?
(I'm not trying to paint you into a corner with this statement, you're
perfectly entitled to have a different opinion for this case as no two
cases are identical)
Further thoughts.. (arguing both sides)
Steve gave an example in this very thread where the C++ behaviour can
cause errors for users/consumers of the classes so that would count as a
penalty for the C++ case. Conversely you could argue that at least this
isn't a silent error as the problems Walter describe are (from memory -
pls correct me if I haven't remember it correctly).
You could argue D with it's single inheritance and interfaces is closer
to Java than C++. In a situation where you have multiple inheritance
it's certainly more likely to be complex in which case the C++ approach
makes it easier to understand and therefore use derived classes
correctly. Conversely you could argue any inheritance is complex enough
and justifies the C++ behaviour.
Regan
More information about the Digitalmars-d
mailing list