Agn*_*ian 7 delegates compiler-errors c++-cli
以下代码导致C3867(...函数调用缺少参数列表...)和C3350(...委托构造函数需要2个参数...).我究竟做错了什么?
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));
}
};
Run Code Online (Sandbox Code Playgroud)
Gro*_*roo 13
在C++/CLI中,您必须传递包含该函数的类型的实际实例:
array<int> ^even = Array::FindAll(
numbers, gcnew Predicate<int>(this, &Test::IsEven));
Run Code Online (Sandbox Code Playgroud)
(或制定IsEven方法static)