3

Why it doesn't work in C++/CLI ?

_list->Remove(_list->Find(x => x.Inode == 2));

I received an error error C2065: 'x' : undeclared identifier

Artem Kyba
  • 855
  • 1
  • 11
  • 30
  • This is not possible to troubleshoot without further context. Posting more of your code would help. – Edward Apr 04 '14 at 14:07
  • 1
    Because that's C# syntax. See http://www.codeproject.com/Articles/277612/Using-lambdas-Cplusplus-vs-Csharp-vs-Cplusplus-CX – Alex K. Apr 04 '14 at 14:07
  • 4
    C++/CLI doesn't support lambda expressions. The language was frozen in 2005, no new bells and whistles were added to it since then. You'll need to use a delegate explicitly. C++11 got lambdas but they are not compatible with C++/CLI. – Hans Passant Apr 04 '14 at 15:42

2 Answers2

1

@Hans Passant's comment is the answer, so I'm just pasting it here:

C++/CLI doesn't support lambda expressions. The language was frozen in 2005, no new bells and whistles were added to it since then. You'll need to use a delegate explicitly. C++11 got lambdas but they are not compatible with C++/CLI. – Hans Passant

Matt Smith
  • 17,026
  • 7
  • 53
  • 103
1

As Hans Passant commented, C++/CLI doesn't support lambda notation. If you need to use the Find method it can be done by creating your own delegate and invoking it with a new instance of

_list->Find(gcnew Predicate<T>(gcnew &MyDelegate(params)))

Here's a link to a snippet that I used: Custom List::Find() Method in C++/CLI

Community
  • 1
  • 1
A.Clymer
  • 472
  • 3
  • 9