views:

693

answers:

1

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));
     }
    };
+5  A: 

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));

(or make your IsEven method static)

Groo
And I also forgot the ampersand. Thanks.
Vulcan Eager