Bind object to member function
BCS
BCS at pathlink.com
Mon Aug 14 09:37:00 PDT 2006
Li Jie wrote:
> class Test{
> void a(int n){}
> }
>
> auto a = &Test.a;
> auto t = new Test;
> a(t, 1); // or: a.bind(t); a(1);
>
> Is this supported?
something like this works
# // inline function
#auto b = function(Test t)
# {
# t.a;
# }
#
#auto t = new Test;
#
# // call function
#b(t);
Add parameters to the function if a has parameters.
Also say Test has a "real c(char[],int,int)" and you don't want to set
all of it's parameters, you can do this:
#int i,j;
#
#auto d = (Test test, char[] ch)
# {
# // take ch as arg
# // pull i,j from context
# return test.c(ch,i,j);
# }
#
# // only need one peram here
#auto ret = d(t,"foo");
More information about the Digitalmars-d-learn
mailing list