delegates icon indicating copy to clipboard operation
delegates copied to clipboard

What syntax to use member function/method with service delegate?

Open sfinktah opened this issue 9 years ago • 0 comments

Following on from test and example code, s.registerDelegate(d) will fail if d is not a free function.

void test() {
//  Free function works fine
//  auto d = make_delegate(&myFreeFunction);

//  But member methods will create an error
    A a;
    auto d = make_delegate(&A::simple, a);

    Service s;
    s.registerDelegate(d);
//  Error (active)  a reference of type "ServiceDelegate &" (not
//  const-qualified) cannot be initialized with a value of type
//  "dlgt::delegate<void (A::*)()>"

//  Error   C2664   'void Service::registerDelegate(ServiceDelegate &)': cannot
//  convert argument 1 from 'dlgt::delegate<void (__cdecl A::* )(void)>' to
//  'ServiceDelegate &'

    s.notifyDelegate();
}

sfinktah avatar Aug 21 '16 05:08 sfinktah