Is it possible to use the new lambda expressions in Visual C++ 2010 as CLR event handlers? I’ve tried the following code:
SomeEvent += gcnew EventHandler(
[] (Object^ sender, EventArgs^ e) {
// code here
}
);
It results in the following error message:
error C3364: ‘System::EventHandler’ : invalid argument for delegate constructor; delegate target needs to be a pointer to a member function
Am I attempting the impossible, or is simply my syntax wrong?
No can do, the C++/CLI compiler didn’t get updated to accept the lambda syntax. Fairly ironic btw given the head-start that managed code had.