List<T> Find method in C++/CLI

百般思念 提交于 2020-01-15 08:44:07

问题


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


回答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




回答2:


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



来源:https://stackoverflow.com/questions/22864844/listt-find-method-in-c-cli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!