Nested classes again.

Markus Dangl danglm at in.tum.de
Sun May 21 06:54:39 PDT 2006


Another problem with my nested classes: I expected this program to print 
"Hello" but it throws a "Error: Access Violation" instead. The only way 
around this seems to be to redeclare Bar,bar and the constructor in 
Foo2... What's wrong?

# module nestedclass2;
#
# private import std.stdio;
#
# class Foo
# {
#     class Bar
#     {
#         void doSayHello()
#         {
#             sayHello();
#         }
#     }
#     Bar bar;
#
#     void sayHello()
#     {
#         writefln("Hello");
#     }
#
#     this()
#     {
#         bar = new Bar();
#     }
# }
#
# class Foo2 : Foo
# {
# }
#
# int main(char[][] argv)
# {
#     Foo2 foo = new Foo2();
#     foo.bar.doSayHello();
#
#     return 0;
# }



More information about the Digitalmars-d-learn mailing list