Thread overview
Nested classes again.
May 21, 2006
Markus Dangl
May 21, 2006
Frank Benoit
May 21, 2006
Markus Dangl
May 23, 2006
Oskar Linde
May 23, 2006
Deewiant
May 24, 2006
Markus Dangl
May 21, 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;
# }
May 21, 2006
This seems to me, like a bug, which will be fixed in the next dmd version. Please try to add a default ctor to Foo2. Perhaps this helps.
May 21, 2006
Frank Benoit schrieb:
> This seems to me, like a bug, which will be fixed in the next dmd version.
> Please try to add a default ctor to Foo2. Perhaps this helps.

Tried it, it didn't help.
May 23, 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
May 23, 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.
May 24, 2006
> It worked for me, too, with DMD 0.157 under Windows.
> 
> However, compiled with -inline, it throws an Access Violation.

Oh right, it was DMD 0.157 under Windows, an i was using "inline" too.
I'll file a bug report.