Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Compiling C++/CLI Delegate call using Predicate with Array::FindAll()

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));
        }
    };
like image 551
Agnel Kurian Avatar asked Mar 16 '09 08:03

Agnel Kurian


1 Answers

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)

like image 186
Groo Avatar answered Sep 20 '22 15:09

Groo