digitalmars.D.learn - Abstract Classes
- IM (21/21) Dec 05 2017 Assume the following:
- =?UTF-8?Q?Ali_=c3=87ehreli?= (6/36) Dec 05 2017 Just remove the override keywords in this case. No function is
- IM (3/10) Dec 06 2017 I believe this is a bug, and a confusing one to be honest. Can
- =?UTF-8?Q?Ali_=c3=87ehreli?= (6/18) Dec 06 2017 There is no owners field when opening an issue. To get you started on
- IM (2/27) Dec 06 2017 Done: https://issues.dlang.org/show_bug.cgi?id=18041. Thanks!
- bauss (23/44) Dec 05 2017 bar() is not a virtual function, but is defined in the interface
Assume the following: interface IFace { void foo(); void bar(); } abstract class A : IFace { override void foo() {} } class B : A { override void bar() {} } Now why this fails to compiler with the following message: --->>> function bar does not override any function, did you mean to override 'IFace.bar()'? <<<--- Obviously, I meant that, since the abstract class A implements IFace, and B derives from A. Do I need to declare IFace's unimplemented methods in A as abstract? If yes, why? Isn't that already obvious enough (any unimplemented virtual function is abstract)?
Dec 05 2017
On 12/05/2017 11:23 PM, IM wrote:Assume the following: interface IFace { void foo(); void bar(); } abstract class A : IFace { override void foo() {} } class B : A { override void bar() {} } Now why this fails to compiler with the following message: --->>> function bar does not override any function, did you mean to override 'IFace.bar()'? <<<--- Obviously, I meant that, since the abstract class A implements IFace, and B derives from A. Do I need to declare IFace's unimplemented methods in A as abstract? If yes, why? Isn't that already obvious enough (any unimplemented virtual function is abstract)?Just remove the override keywords in this case. No function is overriding any implementation here, they both implement an interface function. The fact that override can be used for A.foo can be seen as an inconsistency or a bug. Ali
Dec 05 2017
On Wednesday, 6 December 2017 at 07:54:21 UTC, Ali Çehreli wrote:On 12/05/2017 11:23 PM, IM wrote:I believe this is a bug, and a confusing one to be honest. Can you please help file one against the right owners? Thanks![...]Just remove the override keywords in this case. No function is overriding any implementation here, they both implement an interface function. The fact that override can be used for A.foo can be seen as an inconsistency or a bug. Ali
Dec 06 2017
On 12/06/2017 03:01 PM, IM wrote:On Wednesday, 6 December 2017 at 07:54:21 UTC, Ali Çehreli wrote:There is no owners field when opening an issue. To get you started on the bug tracking system, please create this one yourself: :) https://issues.dlang.org/ Thank you, AliOn 12/05/2017 11:23 PM, IM wrote:I believe this is a bug, and a confusing one to be honest. Can you please help file one against the right owners? Thanks![...]Just remove the override keywords in this case. No function is overriding any implementation here, they both implement an interface function. The fact that override can be used for A.foo can be seen as an inconsistency or a bug. Ali
Dec 06 2017
On Wednesday, 6 December 2017 at 23:16:54 UTC, Ali Çehreli wrote:On 12/06/2017 03:01 PM, IM wrote:Done: https://issues.dlang.org/show_bug.cgi?id=18041. Thanks!On Wednesday, 6 December 2017 at 07:54:21 UTC, Ali Çehreliwrote:isOn 12/05/2017 11:23 PM, IM wrote:[...]Just remove the override keywords in this case. No functioninterfaceoverriding any implementation here, they both implement anbe seen asfunction. The fact that override can be used for A.foo canCan youan inconsistency or a bug. AliI believe this is a bug, and a confusing one to be honest.please help file one against the right owners? Thanks!There is no owners field when opening an issue. To get you started on the bug tracking system, please create this one yourself: :) https://issues.dlang.org/ Thank you, Ali
Dec 06 2017
On Wednesday, 6 December 2017 at 07:23:29 UTC, IM wrote:Assume the following: interface IFace { void foo(); void bar(); } abstract class A : IFace { override void foo() {} } class B : A { override void bar() {} } Now why this fails to compiler with the following message: --->>> function bar does not override any function, did you mean to override 'IFace.bar()'? <<<--- Obviously, I meant that, since the abstract class A implements IFace, and B derives from A. Do I need to declare IFace's unimplemented methods in A as abstract? If yes, why? Isn't that already obvious enough (any unimplemented virtual function is abstract)?bar() is not a virtual function, but is defined in the interface IFace and thus you don't need to override it in B. The same goes for foo() which I'd argue should have given same error. What you possibly wanted to do is this: interface IFace { void foo(); void bar(); } abstract class A : IFace { abstract void bar(); // All child classes must implement bar and override it abstract void foo(); // Since A implements IFace we must implement both bar() and foo() // However it's an abstract class, so we can leave implementation // up to the children. } class B : A { override void bar() {} override void foo() {} }
Dec 05 2017