www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - confusion between conversion between member function delegate and property call

reply Simon Hudon <Simon.hudon gmail_removethat.com> writes:
I have the following code:

class MyClass {
public:
    void memberFunction ()
    {   v = 3;
    }
private:
    int v;
}

void main() {
    auto c = new MyClass;
    void delegate () a = c.memberFunction; // Produces an error voids have no
value
}

What I think is appening is that DMD interprets c.memberFunction as a property
call expression that it can then put into a delegate as a lazy evaluated
expression.  Instead, what I would like it to do is that a points to a call of
memberFunction on the object referenced by c.

Please tell me if you know an elegant way to do it.

Thanks
Simon Hudon
Aug 23 2006
parent Tom S <h3r3tic remove.mat.uni.torun.pl> writes:
Simon Hudon wrote:
 
 I have the following code:
 
 class MyClass {
 public:
     void memberFunction ()
     {   v = 3;
     }
 private:
     int v;
 }
 
 void main() {
     auto c = new MyClass;
     void delegate () a = c.memberFunction; // Produces an error voids have no
 value
 }
 
 What I think is appening is that DMD interprets c.memberFunction as a property
 call expression that it can then put into a delegate as a lazy evaluated
 expression.  Instead, what I would like it to do is that a points to a call of
 memberFunction on the object referenced by c.
 
 Please tell me if you know an elegant way to do it.
 
 Thanks
 Simon Hudon
void delegate () a = &c.memberFunction;
Aug 23 2006