www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Nested classes again.

reply Markus Dangl <danglm in.tum.de> writes:
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
next sibling parent reply Frank Benoit <keinfarbton nospam.xyz> writes:
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
parent Markus Dangl <danglm in.tum.de> writes:
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 21 2006
prev sibling parent reply Oskar Linde <oskar.lindeREM OVEgmail.com> writes:
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
parent reply Deewiant <deewiant.doesnotlike.spam gmail.com> writes:
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 23 2006
parent Markus Dangl <danglm in.tum.de> writes:
 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.
May 24 2006