digitalmars.D.learn - How to override impure function from pure function
- Nikhil Jacob (5/5) Dec 12 2016 In the D spec for pure functions it says that a pure function can
- Nicholas Wilson (21/26) Dec 12 2016 what this means is
- Nikhil Jacob (5/34) Dec 12 2016 I mistook the original statement to mean that an impure function
- Nicholas Wilson (3/7) Dec 12 2016 Yeah you can't do that, except in a debug statement. You can
In the D spec for pure functions it says that a pure function can override "can override an impure function, but an impure function cannot override a pure one" Can anyone help me how to do this ?
Dec 12 2016
On Tuesday, 13 December 2016 at 04:48:11 UTC, Nikhil Jacob wrote:In the D spec for pure functions it says that a pure function can override "can override an impure function, but an impure function cannot override a pure one" Can anyone help me how to do this ?what this means is class Foo { void foo() { ... } } class Bar : Foo { override void foo() pure { ... } } is allowed. but int someglobal; class Foo { void foo() pure { ... } } class Bar : Foo { override void foo() { someglobal = 42; } } in not.
Dec 12 2016
On Tuesday, 13 December 2016 at 05:10:02 UTC, Nicholas Wilson wrote:On Tuesday, 13 December 2016 at 04:48:11 UTC, Nikhil Jacob wrote:I mistook the original statement to mean that an impure function can be called from a pure function with some manual overrides. Thank you for the clarification.In the D spec for pure functions it says that a pure function can override "can override an impure function, but an impure function cannot override a pure one" Can anyone help me how to do this ?what this means is class Foo { void foo() { ... } } class Bar : Foo { override void foo() pure { ... } } is allowed. but int someglobal; class Foo { void foo() pure { ... } } class Bar : Foo { override void foo() { someglobal = 42; } } in not.
Dec 12 2016
On Tuesday, 13 December 2016 at 05:13:01 UTC, Nikhil Jacob wrote:I mistook the original statement to mean that an impure function can be called from a pure function with some manual overrides. Thank you for the clarification.Yeah you can't do that, except in a debug statement. You can however cheat with SetFunctionAttributes (from std.traits).
Dec 12 2016