Delegates and nested classes...
Markus Dangl
danglm at in.tum.de
Sun May 21 06:02:30 PDT 2006
I expected the following code to print "Hello", but it doesn't. Since a
nested class has access to its enclosing classes' members, i assumed it
could also return delegates to its methods. Where am i wrong - or is it
a bug?
# module nestedclass;
#
# private import std.stdio;
#
# class Foo
# {
# class Bar
# {
# void delegate() getDelegate()
# {
# return &sayHello;
# }
# }
# Bar bar;
#
# void sayHello()
# {
# writefln("Hello");
# }
#
# this()
# {
# bar = new Bar();
# }
# }
#
# int main(char[][] argv)
# {
# Foo foo = new Foo();
# void delegate() sayHello = foo.bar.getDelegate();
# sayHello();
#
# return 0;
# }
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: nestedclass.d
Url: http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20060521/6029a077/attachment.diff
More information about the Digitalmars-d-learn
mailing list