www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Q: Delegate Literal in Class Member

reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
In this code, is the delegate literal a stack delegate (i.e. the builtin 
ptr points to the stack frame), or a class delegate (i.e. the builting 
ptr points to 'this')?  If the former, is there some way to make it a 
class delegate?

class Foo {
   void delegate() GetDelegate() {
     return delegate void() {
              return fooFunc(3);
     };
   }

   void fooFunc(int x) { ... }
}

If the delegate literal is a stack delegate, then I can't return it 
(since the stack frame goes away).  But if it's a class delegate, then I 
can return it from the function and let it be called later from any stack.
May 18 2004
parent reply "Walter" <newshound digitalmars.com> writes:
A class delegate can only be formed from a class member function.

"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:c8dof9$1vuf$1 digitaldaemon.com...
 In this code, is the delegate literal a stack delegate (i.e. the builtin
 ptr points to the stack frame), or a class delegate (i.e. the builting
 ptr points to 'this')?  If the former, is there some way to make it a
 class delegate?

 class Foo {
    void delegate() GetDelegate() {
      return delegate void() {
               return fooFunc(3);
      };
    }

    void fooFunc(int x) { ... }
 }

 If the delegate literal is a stack delegate, then I can't return it
 (since the stack frame goes away).  But if it's a class delegate, then I
 can return it from the function and let it be called later from any stack.
May 19 2004
parent reply Russ Lewis <spamhole-2001-07-16 deming-os.org> writes:
I'm confused.  Isn't that exactly what's going on here?  Or are you 
saying that a class delegate can only be formed with the syntax:
	<var>.memberFuncName
?

Walter wrote:
 A class delegate can only be formed from a class member function.
 
 "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
 news:c8dof9$1vuf$1 digitaldaemon.com...
 
In this code, is the delegate literal a stack delegate (i.e. the builtin
ptr points to the stack frame), or a class delegate (i.e. the builting
ptr points to 'this')?  If the former, is there some way to make it a
class delegate?

class Foo {
   void delegate() GetDelegate() {
     return delegate void() {
              return fooFunc(3);
     };
   }

   void fooFunc(int x) { ... }
}

If the delegate literal is a stack delegate, then I can't return it
(since the stack frame goes away).  But if it's a class delegate, then I
can return it from the function and let it be called later from any stack.
May 19 2004
parent "Walter" <newshound digitalmars.com> writes:
No, you've created a delegate literal, which is a nested function. Try
instead &member.

"Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
news:c8gkai$d42$1 digitaldaemon.com...
 I'm confused.  Isn't that exactly what's going on here?  Or are you
 saying that a class delegate can only be formed with the syntax:
 <var>.memberFuncName
 ?

 Walter wrote:
 A class delegate can only be formed from a class member function.

 "Russ Lewis" <spamhole-2001-07-16 deming-os.org> wrote in message
 news:c8dof9$1vuf$1 digitaldaemon.com...

In this code, is the delegate literal a stack delegate (i.e. the builtin
ptr points to the stack frame), or a class delegate (i.e. the builting
ptr points to 'this')?  If the former, is there some way to make it a
class delegate?

class Foo {
   void delegate() GetDelegate() {
     return delegate void() {
              return fooFunc(3);
     };
   }

   void fooFunc(int x) { ... }
}

If the delegate literal is a stack delegate, then I can't return it
(since the stack frame goes away).  But if it's a class delegate, then I
can return it from the function and let it be called later from any
stack.

May 19 2004