Overloading/Inheritance issue
Regan Heath
regan at netmail.co.nz
Thu Aug 2 01:32:31 PDT 2007
Derek Parnell wrote:
> On Wed, 01 Aug 2007 17:37:58 -0400, Steve Schveighoffer wrote:
>> This is very counterintuitive...
>
>> My point basically is why should a coder be forced to declare
>> an alias when realistically there is no reason they would
>> NOT want to declare the alias?
>
> Oh don't get me wrong, I too think that the current rules are totally daft.
> I mean, why does one go to the trouble of deriving one class from another
> if its not to take advantage of members in the parent class?
>
> I vaguely recall Walter saying that he decided to do it this way because it
> is easy to implement this rule into the compiler and it makes the compiler
> run faster. (I am paraphrasing from memory, so I could be totally wrong).
>
> If this is so, then it strikes me that the language is this way in order to
> make life easier for compiler writers than for D coders, which is just not
> right in my POV.
You're not recalling Walter reasoning correctly. :)
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, I've linked his original arguments at the end of this post.
#include <stdio.h>
class Base
{
public:
void foo()
{
printf("Base::foo()\n");
}
void foo(int i)
{
printf("Base::foo(i)\n");
}
};
class Child : Base
{
public:
void foo(int i)
{
printf("Child::foo(i)\n");
}
};
void main()
{
Child c;
c.foo();
}
Some references to Walters original comments on the topic. Anyone who
is interested should probably read this entire thread (though it is a
monster) to get a really clear picture of the problems associated with this:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=6975
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=7053
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=7063
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=7137
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=7149
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=7057
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=7072
I could keep linking all day... these are all from the same thread so
starting at the top and reading the whole thread should give you a fair
idea of the issues.
Regan
More information about the Digitalmars-d
mailing list