digitalmars.D.learn - Does D have syntax for adding subscopes to classes?
- GregoryP (16/16) Aug 12 2015 I'm just wondering if, or how much of the following is possible
- sigod (3/19) Aug 12 2015 [Nested classes][0] maybe?
- Adam D. Ruppe (30/31) Aug 12 2015 Example with them:
- Xinok (3/5) Aug 12 2015 That's the idea I had except I would use a struct instead because
I'm just wondering if, or how much of the following is possible in some way in D: class Foo { int x; sub Bar { int x; int getFooX(){ return super.x; } sub FooBar { int x; int y; int addXes(){ return x + super.x + super.super.x; } } } } Where the Xes are accessible outside the class by Foo.x, Foo.Bar.x, Foo.Bar.FooBar.x.
Aug 12 2015
On Wednesday, 12 August 2015 at 15:21:28 UTC, GregoryP wrote:I'm just wondering if, or how much of the following is possible in some way in D: class Foo { int x; sub Bar { int x; int getFooX(){ return super.x; } sub FooBar { int x; int y; int addXes(){ return x + super.x + super.super.x; } } } } Where the Xes are accessible outside the class by Foo.x, Foo.Bar.x, Foo.Bar.FooBar.x.[Nested classes][0] maybe? [0]: http://dlang.org/class.html#nested
Aug 12 2015
On Wednesday, 12 August 2015 at 15:24:43 UTC, sigod wrote:[Nested classes][0] maybe?Example with them: class Foo { int x; class Bar_ { // underscore cuz we have to declare variable too int x; int getFooX() { return this.outer.x; } class FooBar_ { int x; int y; int addXes() { return x + this.outer.x + this.outer.outer.x; } } FooBar_ FooBar; this() { FooBar = new FooBar_; // the var must also be initialized in a ctor } } Bar_ Bar; this() { Bar = new Bar_; // same out here } } void main() { auto foo = new Foo(); import std.stdio; writeln(foo.Bar.FooBar.addXes()); }
Aug 12 2015
On Wednesday, 12 August 2015 at 15:47:37 UTC, Adam D. Ruppe wrote:Example with them: ...That's the idea I had except I would use a struct instead because using a class requires a second allocation.
Aug 12 2015