reference class parent's function
Stewart Gordon
smjg_1998 at yahoo.com
Wed May 2 17:18:30 PDT 2007
"okibi" <okibi at ratedo.com> wrote in message
news:f17r27$28ku$1 at digitalmars.com...
<snip>
> Nobody has any ideas?
I have a few that will help you a lot in general:
1. Post the exact code that you're trying. If it's quite long, trim it to a
minimal version that you've tested and found to show the same problem.
2. Post the exact error messages you receive when you try the code you've
posted.
As it happens, this works for me:
----- okibi1.d -----
import okibi2;
import std.stdio;
class class1 {
class2 c2;
// init needs to be in constructor since it allocates at run-time
this() { c2 = new class2(this); }
public void writeFunc(char[] myStr) {
writefln("%s", myStr);
}
}
void main() {
auto c = new class1;
c.c2.foo();
}
----- okibi2.d -----
import okibi1;
class class2 {
class1 c1;
this(class1 c) { c1 = c; }
void foo() {
c1.writeFunc("hello world");
}
}
----------
Stewart.
More information about the Digitalmars-d-learn
mailing list