Internal delegate and Stack Overflow

BCS ao at pathlink.com
Fri Nov 28 16:08:28 PST 2008


Reply to TSalm,

> Hello,
> 
> I would do something like this, but this return me an execution error
> : object.Exception: Stack Overflow
> 
> // --------CODE--------
> class A
> {
> void delegate() dg;
> void doIt()
> {
> dg();
> }
> }
> class B
> {
> A a;
> this()
> {
> a = new A;
> a.dg = { doSomething(); };
> }
> void doSomething() { }
> }
> void main()
> {
> auto b = new B;
> b.a.doIt();
> }
> // ------END CODE------
> 
> Is this a bug or have I do something wrong ?
> Thanks in advance for your help,
> TSalm

If this is d1.0 the error is that you are allowing an anon delegate to escape 
the enclosing function.

a.dg = &this.doSomething;  // this would be ok if that helps.


 if it is 2.0, I think this is correct.




More information about the Digitalmars-d-learn mailing list