I'm updating some old Managed C++ code with lines like this:
instanceOfEventSource->add_OnMyEvent(
new EventSource::MyEventHandlerDelegate(this, MyEventHandlerMethod) );
where
What is the right syntax for this in C++/CLI?
The syntax is similar to C#'s, in other words, +=
is overloaded to make this possible:
instanceOfEventSource.MyEvent +=
gcnew EventSource::MyEventHandlerDelegate(this, &MyClass::MyEventHandlerMethod);
Analogously for removal. Unlike C#, however, you may not omit the explicit instantiation of the event handler delegate so this produces quite long-winded code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With