www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Method Inheritance

reply John Demme <me teqdruid.com> writes:
The below code doesn't work unless you uncomment out the alias.  I think the
reason for this was explained to me at some point, but I don't remember. Or
is it a bug?  I think it should be a bug.

~John Demme 

class A
{
        void foo (int i)
        {}
}

class B: A
{
        void foo (int i, int j)
        {}

        /+alias A.foo foo;+/
}

void main()
{
        B b = new B();
        b.foo(5,7);
        b.foo(7);
}
May 13 2006
next sibling parent Lars Ivar Igesund <larsivar igesund.net> writes:
John Demme wrote:

 The below code doesn't work unless you uncomment out the alias.  I think
 the reason for this was explained to me at some point, but I don't
 remember. Or
 is it a bug?  I think it should be a bug.

It's by design, believe it or not ;) It's been a while since the last discussions I think, but it has to do with the overload rules (which apparently is the same as in C++, but different from those in Java). Walter is trying to make these rules simple, although IIRC, the corresponding Java-type rules were equally simple to understand for us mundane. I don't remember how it affected compiler complexity.
 
 ~John Demme
 
 class A
 {
         void foo (int i)
         {}
 }
 
 class B: A
 {
         void foo (int i, int j)
         {}
 
         /+alias A.foo foo;+/
 }
 
 void main()
 {
         B b = new B();
         b.foo(5,7);
         b.foo(7);
 }

-- Lars Ivar Igesund blog at http://larsivi.net DSource & #D: larsivi
May 14 2006
prev sibling parent reply Bruno Medeiros <brunodomedeirosATgmail SPAM.com> writes:
John Demme wrote:
 The below code doesn't work unless you uncomment out the alias.  I think the
 reason for this was explained to me at some point, but I don't remember. Or
 is it a bug?  I think it should be a bug.
 
 ~John Demme 
 
 class A
 {
         void foo (int i)
         {}
 }
 
 class B: A
 {
         void foo (int i, int j)
         {}
 
         /+alias A.foo foo;+/
 }
 
 void main()
 {
         B b = new B();
         b.foo(5,7);
         b.foo(7);
 }

It was mentioned in: news://news.digitalmars.com:119/e3knre$2vp1$1 digitaldaemon.com namely:
 In http://www.digitalmars.com/d/function.html , "Function Inheritance
 and Overriding" it is said:
 "However, when doing overload resolution, the functions in the base
 class are not considered:"
 If that is the ideal behavior, well, that I'm not sure...

-- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
May 19 2006
parent John Demme <me teqdruid.com> writes:
In article <e4lnue$s42$1 digitaldaemon.com>, Bruno Medeiros says...
John Demme wrote:
 The below code doesn't work unless you uncomment out the alias.  I think 


 reason for this was explained to me at some point, but I don't remember. Or
 is it a bug?  I think it should be a bug.
 
 ~John Demme 
 
 class A
 {
         void foo (int i)
         {}
 }
 
 class B: A
 {
         void foo (int i, int j)
         {}
 
         /+alias A.foo foo;+/
 }
 
 void main()
 {
         B b = new B();
         b.foo(5,7);
         b.foo(7);
 }

It was mentioned in: news://news.digitalmars.com:119/e3knre$2vp1$1 digitaldaemon.com namely:
 In http://www.digitalmars.com/d/function.html , "Function Inheritance
 and Overriding" it is said:
 "However, when doing overload resolution, the functions in the base
 class are not considered:"
 If that is the ideal behavior, well, that I'm not sure...

-- Bruno Medeiros - CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D

Ach!! ... Just a pain in the ass in my opinion-- I have to remember to put in aliases for each method. Thanks for the links. ~John
May 20 2006