samedi 11 décembre 2021

Remve element from vector with lambda

This code does not compile.

            std::remove_if( m_selectedFields.begin(),
                            m_selectedFields.end(),
                            [](const FieldWin *obj, FieldWin *m_draggingField)
                            {
                                obj == m_draggingField;
                            } );

The m_selectedFields is a vector and its a member of the class, defined as std::vector<Foo *> m_selectedFields. The m_draggingField is also a member of the class, defined as Foo m_draggingField.

What am I doing wrong?

The errors are:

error C2064: term does not evaluate to a function taking 1 arguments
note: class does not define an 'operator()' or a user defined conversion operator to a pointer-to-function or reference-to-function that takes appropriate number of arguments

I think lambda function should have only one argument, but then how do I pass the element that needs to be removed?

Aucun commentaire:

Enregistrer un commentaire