October 07, 2002 Re: Performance. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Evan McClanahan | I quote from the D programming language specification: "Templates cannot be used to add non-static members or functions to classes." I guess that this cannot be done because the compiler will have problems to decide if a method should be virtual or not. Can we add final methods to a class? I can't see a reason why we shouldn't. e.g.: class C { template insideC(T, U) { final func(out T a, in U b) {a = cast(T) b;} }} instance insideC(int, float), insideC(float, int), insideC(byte, bit); |
October 07, 2002 Re: Performance. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dario | I realized that what I've written is nosense... What I meant is a way to provide a quick method to add methods to a class using templates. In the example you see a kinda anonymous template instances (to be accessed as: C c; c.func(12, 12.0);). But maybe it doesn't fit well in the language. > I quote from the D programming language specification: > "Templates cannot be used to add non-static members or functions to > classes." > > I guess that this cannot be done because the compiler will have problems to > decide if a method should be virtual or not. > Can we add final methods to a class? I can't see a reason why we shouldn't. > > e.g.: > class C > { > template insideC(T, U) > { > final func(out T a, in U b) {a = cast(T) b;} > }} > > instance insideC(int, float), insideC(float, int), insideC(byte, bit); |
October 07, 2002 Re: Performance. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dario | "Dario" <supdar@yahoo.com> wrote in message news:ans1pv$pch$1@digitaldaemon.com... > I realized that what I've written is nosense... > What I meant is a way to provide a quick method to add methods to a class > using templates. In the example you see a kinda anonymous template instances > (to be accessed as: C c; c.func(12, 12.0);). > But maybe it doesn't fit well in the language. You can add methods, they'll just need to be static. |
Copyright © 1999-2021 by the D Language Foundation