Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Animal {
- int delegate(int) fly;
- void delegate() crawl;
- }
- // Use structs
- struct Bird {
- Animal animal;
- alias animal this;
- Wing[] wings;
- this()
- {
- animal.fly = &flyImpl;
- anumal.crawl = &crawlImpl;
- }
- int flyImpl(int) { return use(wings); }
- void crawlImpl() { }
- }
- // Use closures
- Animal makeBird()
- {
- Animal bird;
- Wing wings;
- bird.fly = (int) { return use(wings); }
- bird.crawl = () {};
- return bird;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement