Overloading/Inheritance issue

Sean Kelly sean at f4.ca
Thu Aug 2 09:33:37 PDT 2007


Regan Heath wrote:
> Steve Schveighoffer wrote:
>> Regan Heath Wrote:
> 
>  > I was assuming that C++ got it right.  More than
>> I can't believe that C++ is not right, I'm surprised I never had
>> problems with it...
> 
> It's truly odd that no-one seems to have a problem with it in C++.  It's 
> not as if C++ even has 'alias' so it cannot pull symbols in, you're left 
> re-implementing in the derived class.  Perhaps everyone just does that 
> without thinking about it.

'using' serves this purpose in C++.

>> However, I think it should be changed.  Not sure if it will, as it
>> seems there  is already a precedent.  In my opinion, the base class
>> should be examined if the derived class does not provide a suitable
>> match.  I can't see how this would cause too much of a performance
>> hit
> 
> Performance isn't the reason against the Java behaviour, here is Walters 
> explaination:
> 
> <quote Walter quoting Stroustrup>
> 
> Stroustrup gives two examples (slightly modified here):
> 
> ---------------------------------
> class X1 { void f(int); }
> 
> // chain of derivations X(n) : X(n-1)
> 
> class X9: X8 { void f(double); }
> 
> void g(X9 p)
> {
>     p.f(1);    // X1.f or X9.f ?
> }
> -----------------------------------
> His argument is that one can easilly miss an overload of f() somewhere in a
> complex class heirarchy, and argues that one should not need to understand
> everything about a class heirarchy in order to derive from it.

One key difference between D and C++ in this regard is that class 
methods in D are virtual by default, while in C++ they are not.  One 
could argue that this changes the implications of the "is a" 
relationship in D.  However, I do think the current rule is less 
error-prone, once understood.


Sean



More information about the Digitalmars-d mailing list