编译C ++ / CLI时出错使用带有Array :: FindAll()的Predicate调用委托调用 [英] Error Compiling C++/CLI Delegate call using Predicate with Array::FindAll()

查看:226
本文介绍了编译C ++ / CLI时出错使用带有Array :: FindAll()的Predicate调用委托调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码导致C3867(...函数调用缺少参数列表...)和C3350(...委托构造函数期望2个参数...)。我做错了什么?

The following code results in C3867 (...function call missing argument list...) and C3350 (...a delegate constructor expects 2 argument(s)...). What am I doing wrong?

    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
    	bool IsEven(int i){
    		return (i % 2) == 0;
    	}

    	Form1(void)
    	{
    		numbers = gcnew array<int>{
    			1, 2, 3, 4, 5, 6, 7, 8, 9, 10
    		};

    		array<int> ^even = Array::FindAll(
    			numbers, gcnew Predicate<int>(IsEven));
    	}
    };


推荐答案

在C ++ / CLI中,包含函数的类型:

In C++/CLI you have to pass the actual instance of the type containing the function:

 array<int> ^even = Array::FindAll(
    numbers, gcnew Predicate<int>(this, &Test::IsEven));

(或使您的 IsEven 方法 static

这篇关于编译C ++ / CLI时出错使用带有Array :: FindAll()的Predicate调用委托调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆