digitalmars.D.learn - Alias to single function of object inside class
- ARaspiK (5/5) Jan 16 2018 I have a class Foo, which has functions a(), b(), and c().
- =?UTF-8?Q?Ali_=c3=87ehreli?= (26/30) Jan 16 2018 Why not show it with code? :) Is the following accurate and sufficient?
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().
Jan 16 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
Jan 16 2018