digitalmars.D.bugs - Nested class constructors
- Deewiant (12/12) Oct 14 2005 DMD 0.135, Windows XP Service Pack 2.
- John C (9/20) Oct 15 2005 I'm not 100% sure, but I don't think non-static nested classes can have
- =?utf-8?B?RGF3aWQgQ2nEmcW8YXJraWV3aWN6?= (18/30) Oct 17 2005 Nonstatic nested classes contain secret pointer to enclosing class.
DMD 0.135, Windows XP Service Pack 2.
class A {
class B {
this() {}
void foo() {
new B();
}
}
}
-> "no 'this' for nested class B"
Am I missing something obvious, doing something wrong, or is this a bug?
Oct 14 2005
"Deewiant" <deewiant.doesnotlike.spam gmail.com> wrote in message
news:dionmt$afm$1 digitaldaemon.com...
DMD 0.135, Windows XP Service Pack 2.
class A {
class B {
this() {}
void foo() {
new B();
}
}
}
-> "no 'this' for nested class B"
Am I missing something obvious, doing something wrong, or is this a bug?
I'm not 100% sure, but I don't think non-static nested classes can have
user-defined constructors. Try these:
1) Remove B's constructor. The compiler will add a default which you can
use.
2) change B's declaration to this: static class B. The only downside is you
won't be able to access A's members without maintaining a reference to an
instance of A. But you'll also be able to add your own constructors.
Oct 15 2005
On Fri, 14 Oct 2005 18:52:09 +0200, Deewiant
<deewiant.doesnotlike.spam gmail.com> wrote:
DMD 0.135, Windows XP Service Pack 2.
class A {
class B {
this() {}
void foo() {
new B();
}
}
}
-> "no 'this' for nested class B"
Am I missing something obvious, doing something wrong, or is this a bug?
Nonstatic nested classes contain secret pointer to enclosing class.
Creating them is possible only in that enclosing class (and this pointer
is passed secretly). In A.B.foo() you probably want to create B instance
with secret pointer same as in current instance. You probably could create
A.newB() like that:
class A {
...
B newB() {
return new B();
}
...
}
and use it insted of "new B();". But I think what you're tried could be
allowed to.
--
Dawid Ciężarkiewicz
Oct 17 2005









"John C" <johnch_atms hotmail.com> 