www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Alias to single function of object inside class

reply ARaspiK <arav1025 gmail.com> writes:
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
parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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