Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
May 21, 2006 Nested classes again. | ||||
---|---|---|---|---|
| ||||
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 Re: Nested classes again. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Markus Dangl | 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 Re: Nested classes again. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frank Benoit | 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 Re: Nested classes again. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Markus Dangl | 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 Re: Nested classes again. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Oskar Linde | 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 Re: Nested classes again. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Deewiant | > 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.
|
Copyright © 1999-2021 by the D Language Foundation