Nested classes again.

Oskar Linde oskar.lindeREM at OVEgmail.com
Tue May 23 07:18:05 PDT 2006


Markus Dangl skrev:
> 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;
> # }

What compiler and platform? It works for me (DMD 0.156, Linux).

/Oskar



More information about the Digitalmars-d-learn mailing list