views:

237

answers:

4
+1  Q: 

Lambdas in C++/CLI

How to use lamda expressions in C++/CLI?

A: 

According to What's New in Visual C++ 2010 you can use lambda expressions only in VS2010.

wRAR
what if i have vs-2008? how can i use WindowsFormsSynchronizationContext.Post ?
Xaver
I don't think he's asking about C++0x lambdas, he's asking about using .NET lambdas from C++/CLI
Dean Harding
yes i ask about using .NET lambdas from C++/CLI.
Xaver
Do you mean writing them? I don't think you can write delegates in lambda style in C++/CLI.
wRAR
you right what was being done in the. NET by lambda functions in C + + / CLI is a pointer to a function
Xaver
A: 

I've found this response from a Microsoft employee on the vc blog to a question regarding C++ 0x lambda and managed code interoperability:

You can only pass a variable with a managed type as an argument to a lambda - you can't capture a variable that has a managed type. We have no plans to "merge" lambdas and delegates.

Alexandre Jasmin
+1  A: 

In C#, lambdas are really just syntactic sugar for creating delegates. C++/CLI supports delegates, so you can still do all of the same stuff in C++/CLI that you can do in C#, you just don't get to use the nifty syntax.

Personally, my question would be why are you using C++/CLI in the first place? IMO C++/CLI is only good for writing interop layers between native C++ and C#/.NET and nothing else.

Dean Harding
i agree with you but i already have programm writting on C++/CLI
Xaver