D Paste by naryl
Description: alias this
Hide line numbers

Create new paste
Post a reply
View replies

Paste:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
import std.stdio;

struct A {
    void foo() {
        writefln("A - base struct");
    }
}

struct B {
    string str;
    A a;
    alias a this;
    void f() {
        writefln(str);
    }
}

void main() {
    B b = B("Hello!");
    b.f;
    b.foo;
}

Replies:

    (some replies deleted)