Does D have syntax for adding subscopes to classes?
Adam D. Ruppe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 12 08:47:36 PDT 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());
}
More information about the Digitalmars-d-learn
mailing list