January 16, 2018 Alias to single function of object inside class | ||||
---|---|---|---|---|
| ||||
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(). |
January 16, 2018 Re: Alias to single function of object inside class | ||||
---|---|---|---|---|
| ||||
Posted in reply to ARaspiK | 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
|
Copyright © 1999-2021 by the D Language Foundation