Alias to single function of object inside class

Ali Çehreli acehreli at yahoo.com
Tue Jan 16 19:24:36 UTC 2018


On 01/16/2018 11:00 AM, ARaspiK wrote:
> I have a class Foo, which has functions a(), b(), and c().
> I have a class Bar that has baz, an instance of Foo.
> How do I link Bar.b() -> baz.b() without also linking Foo.a() and Foo.c()?
> I know we can do an alias this, but I only want to link over b().

Why not show it with code? :) Is the following accurate and sufficient?

class Foo {
     void a() {
     }

     void b() {
     }

     void c() {
     }
}

class Bar {
     Foo baz;

     this() {
         baz = new Foo();
     }

     void b() {
         baz.b();
     }
}

void main() {
     auto b = new Bar();
     static assert(!__traits(compiles, b.a()));
     b.b();
     static assert(!__traits(compiles, b.c()));
}

Ali


More information about the Digitalmars-d-learn mailing list