Nested classes again.

Deewiant deewiant.doesnotlike.spam at gmail.com
Tue May 23 07:41:11 PDT 2006


Oskar Linde wrote:
> 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

It worked for me, too, with DMD 0.157 under Windows.

However, compiled with -inline, it throws an Access Violation.



More information about the Digitalmars-d-learn mailing list