digitalmars.D - how does this nested class thing work?
- dennis luehring (39/39) Oct 26 2005 import std.stdio;
- Oskar Linde (7/13) Oct 26 2005 The compiler must know in which context the nested class should be creat...
- dennis luehring (6/31) Oct 26 2005 in the contex of "c"
import std.stdio;
class Class
{
this(){}
class Method1
{
this(){}
int parameter[2];
int result;
void call()
{
result = method1(parameter[0],parameter[1]);
}
}
int method1(int a, int b)
{
return a + b;
}
}
void main()
{
Class c = new Class;
int x = c.method1(10,20);
writef("%d\n",x);
Class.Method1 m1 = new c.Method1();
m1.parameter[0] = 10;
m1.parameter[1] = 20;
m1.call();
writef("%d\n",m1.result);
}
i just try to write an simple oop-wrapper for an method
but i get this compile error:
"nested.d(29): no 'this' for nested class Method1"
from the d-docs
"A non-static nested class can only be instantiated when the necessary
context pointer information is available"
i think there "is" a contex avaiable (through "c")
how can i solve the problem?
thx dennis
Oct 26 2005
In article <djo1km$280i$1 digitaldaemon.com>, dennis luehring says... [snip code]"nested.d(29): no 'this' for nested class Method1" from the d-docs "A non-static nested class can only be instantiated when the necessary context pointer information is available" i think there "is" a contex avaiable (through "c")The compiler must know in which context the nested class should be created.how can i solve the problem?The context has to be available as the current this. You can only instanciate the nested class in this way from within a method of the outer class. /Oskar
Oct 26 2005
Oskar Linde wrote:In article <djo1km$280i$1 digitaldaemon.com>, dennis luehring says... [snip code]in the contex of "c" i don't understand why d can't see the contex in "new c.Method1" c is the outer object(the contex) and Method1 is the inner class wouldnt it be nice to have such a feature?"nested.d(29): no 'this' for nested class Method1"from the d-docs"A non-static nested class can only be instantiated when the necessary context pointer information is available" i think there "is" a contex avaiable (through "c")The compiler must know in which context the nested class should be created.that works for me - thxhow can i solve the problem?The context has to be available as the current this. You can only instanciate the nested class in this way from within a method of the outer class./Oskar
Oct 26 2005








dennis luehring <dl.soluz gmx.net>