digitalmars.D - Overloaded method not inherited
- Garett Bass (26/26) Nov 24 2005 In the following test case, Base.foo(int) is not inherited by Derived. ...
- Manfred Nowak (6/7) Nov 24 2005 According to the rule that non integers are not converted implicitely
- Regan Heath (9/15) Nov 24 2005 I don't see a non-integer -> integer conversion?
- Manfred Nowak (10/11) Nov 24 2005 [...]
- Regan Heath (4/13) Nov 24 2005 No worries. I assumed one of us simply made a mistake.
- Regan Heath (6/9) Nov 24 2005 There are already a few threads on this, have a search you'll see what I...
- Nick (10/18) Nov 26 2005 I think "alias" is a good search term. (Or try "antialias" ;-) You solve...
- Garett Bass (4/13) Nov 27 2005 Nick,
In the following test case, Base.foo(int) is not inherited by Derived. This is also the case in C++, but I wonder whether it is desirable behavior, and if so, why? I find it counterintuitive. ------------ private import std.stdio; abstract class Base { final void foo(int i) { writefln("i = %d", i); } void foo(float f); char[] toString() { return "Base"; } } class Derived : public Base { void foo(float f) { writefln("f = %f", f); } char[] toString() { return "Derived"; } } void main() { int i = 2; float f = 2.5; Derived d = new Derived; d.foo(i); // f = 2.000000 d.foo(f); // f = 2.500000 Base b = d; b.foo(i); // i = 2 b.foo(f); // f = 2.500000 } ------------ Regards, Garett
Nov 24 2005
Garett Bass wrote: [...]I find it counterintuitive.According to the rule that non integers are not converted implicitely to integers this must be a bug, because there is no explicit conversion. -manfred
Nov 24 2005
On Thu, 24 Nov 2005 18:57:47 +0000 (UTC), Manfred Nowak <svv1999 hotmail.com> wrote:Garett Bass wrote: [...]I don't see a non-integer -> integer conversion? I only see a integer -> float conversion, here: int i = 2; ... Derived d = new Derived; d.foo(i); // f = 2.000000 ReganI find it counterintuitive.According to the rule that non integers are not converted implicitely to integers this must be a bug, because there is no explicit conversion.
Nov 24 2005
Regan Heath wrote: [...]I don't see a non-integer -> integer conversion?[...] Woohoo. Me too. The usual error in case one is in a hurry: the stated rule is true, but the assumption that there are any consequences if applied to the concrete case at least untrue. Begging for a pardon for a post witnessing of a mind sometimes some hours behind the appropriate starting point :-) -manfred
Nov 24 2005
On Thu, 24 Nov 2005 22:42:02 +0000 (UTC), Manfred Nowak <svv1999 hotmail.com> wrote:Regan Heath wrote: [...]No worries. I assumed one of us simply made a mistake. ReganI don't see a non-integer -> integer conversion?[...] Woohoo. Me too. The usual error in case one is in a hurry: the stated rule is true, but the assumption that there are any consequences if applied to the concrete case at least untrue. Begging for a pardon for a post witnessing of a mind sometimes some hours behind the appropriate starting point :-)
Nov 24 2005
On Thu, 24 Nov 2005 11:49:52 -0600, Garett Bass <garettbass studiotekne.com> wrote:In the following test case, Base.foo(int) is not inherited by Derived. This is also the case in C++, but I wonder whether it is desirable behavior, and if so, why? I find it counterintuitive.There are already a few threads on this, have a search you'll see what I mean. (I cant think of a good search term, sorry). D follows C++ and Java does it differently, how you we're expecting I imagine. Regan
Nov 24 2005
In article <ops0rjgvj923k2f5 nrage.netwin.co.nz>, Regan Heath says...On Thu, 24 Nov 2005 11:49:52 -0600, Garett Bass <garettbass studiotekne.com> wrote:I think "alias" is a good search term. (Or try "antialias" ;-) You solve it by adding the line "alias Base.foo foo;" to Derived. I found it counterintuitive at first too (in C++), but when someone here (Walter I think) explained the reasoning behind it, I found I actually agree with it. In a complex class hierarchy, it is sometimes hard to keep track of every member defined in all parent classes. If it didn't work the way it does now, you might by accident end up calling a function that you forgot about or didn't even know existed, defined in some base class. NickIn the following test case, Base.foo(int) is not inherited by Derived. This is also the case in C++, but I wonder whether it is desirable behavior, and if so, why? I find it counterintuitive.There are already a few threads on this, have a search you'll see what I mean. (I cant think of a good search term, sorry). D follows C++ and Java does it differently, how you we're expecting I imagine.
Nov 26 2005
Nick, Thanks for the tip. I find this solution acceptable. Regards, GarettI think "alias" is a good search term. (Or try "antialias" ;-) You solve it by adding the line "alias Base.foo foo;" to Derived. I found it counterintuitive at first too (in C++), but when someone here (Walter I think) explained the reasoning behind it, I found I actually agree with it. In a complex class hierarchy, it is sometimes hard to keep track of every member defined in all parent classes. If it didn't work the way it does now, you might by accident end up calling a function that you forgot about or didn't even know existed, defined in some base class. Nick
Nov 27 2005